Create a person - Why not the ID attribute appears (primary key)

03 Oct '13, 02:10 PM
4,658 Views
Forum Forum Starter - Level 3

Hello, I want to add a person but I can not because I don't get the ID Parameter Binding, I think that is the problem!

alt text

This is my Person table, which shows all the attributes at Windows "Parameters Binding" less ID (Primary Key):

alt text

Any suggestions?

Thank you very much,

Jose

 
x 0
Follow
Answer Answer at this question and get points!
Forum Expert - Level 8

Hi, you do not need to bind the ID since it is set as autoincrement. Autoincrement means that is the database that gives the correct value to the primary key, so you do not need to add anything in the model.

When you say that you cannot add a new person, what does it mean? Do you have an error? You can search for errors in the logs of the Web application. The logs are located in the webapp folder under the WEB-INF/log directory. Look for the RTXError.log and open it up. If there's an exception related to the Create Operation , can you report it? The exception should report the ID of the Create Operation in the model.

 
x 1
No Forum Badges

Hi,

the model you created seems to be correct. Usually, you don't need to couple the "id" parameter, because it is automatically generated when the instance (in your case a Person) is created and saved into the database.

You should check the generation type of the ID parameter: in the Domain Model, select the id Attribute of the "Personas" Entity -> Properties panel -> Mapping tab -> "ID Generator" property. The default value is "Increment (select max + 1)". In this case, the "id" is incremented and assigned to the new instance.

You should check if the data of the new person appear in the database, inside the "Personas" table. In this case, the creation ends with success but the new data are not displayed in the page.

You should also check if both the "Person" Details component and the "Person List" component display some attributes. The "Display Attributes" property has to be set in order to see the data in the page.

You could also try to run the "Find Model Problems" command alt text and check the possible warning / errors of the model.

 
x 0
Forum Starter - Level 3

Hi Laura, thanks for your comments!

It is important to let you know that this table is imported from a MySQL database of a system developed in the laboratory where I am.

Then, I check the "ID Generator" property of "Mapping tab" and its value is "Identity (auto increment), ie, that's fine, I think that if!!

Also check inside the Table People and Display Attributes on the Person Details, and never adds. In the same way, and had run the "Find Model Problems" and I didn't find problems.

Therefore, create a table named PersonTest, I replicate the navigational model WebRatio (the same Table Person) and if I can add a new person.

So, that the problem will be:

  • Some property of my table in mysql?,
  • The "ID Generator" property of "Mapping tab" is not "Increment (select max + 1)"?

Thanks again, Jose

 
x 0
No Forum Badges

Hi,

in your case the ID Generator is set to the "Identity (auto increment)". The id attribute is mapped with a key column of a table (e.g. Personas) in the MySQL database. You should check that the id column of the MySQL table (e.g. Personas) has the "Auto Increment" property set. For example:

alt text

or

ALTER TABLE `<database name>`.`<table name>` CHANGE COLUMN `id` `id` <column type> NOT NULL AUTO_INCREMENT;

where in this example <column type> is INT(11).

In this way, the id should be automatically generated when the new instance (e.g. a new person) is created and saved in the database.

 
x 0
Forum Starter - Level 3

Hi Laura, yes, the property of id attribute is "Auto Increment" in my MySQL table.

alt text

I should not change anything and so the problem continues, where, my problem is I can add a new person.

Do you know that I can do to display ID attribute of my window "Parameters Binding" (at frame "Target (Create)")?

Thanks,

Jose

alt text

 
x 0
Forum Starter - Level 3

Hi Michela, thanks for your reply.

Sure, I understand the autoincrement but only wanted to comment that if the autoincrement could be the reason why you do not add a new person.

When I say that I can not add a new person, it's because when I save (button-link), it deletes the tag values ​​and do not add anything in MySQL database. To verify the operation, I access MySQL through the console and I see my list of persons for my web application, in neither case appears the person added.

It is important to note that operations Update, Delete and Read, works well.

Then, I check the RTXError.log and an exception occurs:

04 Oct 2013 06:02:47,417  ERROR [http-8080-3]  (com.webratio.units.operation.rtx.db.CreateUnitService_$$_javassist_53:72) - [5B3DC45A89A43DAABDC22A7960286AD4][cru2]Could not execute service
org.hibernate.exception.GenericJDBCException: could not insert: [com.webratio.webapp.Personas]
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
...
Caused by: java.sql.SQLException: Field 'observaciones' doesn't have a default value
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190)
...

The structure of Person table is:

alt text

Finally, that the MySQL database is the another group working and I'm in another software project, then, I want to use that database and, therefore, should not modify this database structure.

Thank you,

Jose

 
x 0
Forum Starter - Level 3

I forgot, the reason it does not work I think it's because the id field in the window "Parameters Binding" (at frame "Target (Create)"):

alt text

Thanks again,

Jose

 
x 0
Forum Starter - Level 3

Hi Laura and Michela.

I solved this problem.

In the Person table, had 6 field that require a default value. Then, I add in the Form Component of WebRatio (used wizard) and solved the problem.

Thanks again,

Jose

 
x 0
Answer at this question and get points!