• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to save the child details.

 
Shariquddin Mohammed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Am relatively new to Hibernate. However, i am stuck, please help.

Brief Background:

The application is to get information about different machines and store the info in the database.

One main class MachineDetails. Primary key is the IP address. Another child class "HardDiscDetails". There is a foreign key constraint from the main class to the child class.

MachineDetails.hbm.xml:

HardDiscDetails.hbm.xml


Pojo for MachineDetails

Pojo for HardDiscDetails

Servlet

When i run the client i get this exception:
01:47:52,890 ERROR [BasicPropertyAccessor] IllegalArgumentException in class: MachineDetails, getter method of property: NIC_IP
01:47:52,890 INFO [STDOUT] org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of MachineDetails.NIC_IP

I checked and i am getting this error at the step where i save the HardDiscDetails object.
Above i am saving the MachineDetails object (macdel) before i save the child object for HardDiscDetails (hadel). Also as you can see i am able to print out the values of the foreign key column using both the objects. And i when i querry the machine details table on the db(MYSQL) i see the data is saved. But i dont understaqnd why i am not able to persist the child object to the database.

Any help would be greatly appriciated.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use the Code tags to post code, so that the indentation remains. Right now your code is unreadable without indentation.

The Code button in right at the top of when you create a post. Next to Quote and List buttons.

Thanks

Mark
 
Shariquddin Mohammed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Added the code tags. Much clearer now
 
Shariquddin Mohammed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Added the code tags. Yes, it is much clearer now.
 
Raju Goke
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep the two classes under the same package and then try to execute your code.

- Raju
 
Shariquddin Mohammed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your interest, Raju.

Did as you said, but it is still not working.

I wonder why Hibernate is throwing a error when clearly the values are accessible thru the Pojo. Please let me know if i am missing some thing.
 
Andreas Erber
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shariquddin Mohammed,

this might be an issue with the name of your MachineDetails.NIC_IP field and its accessor methods. Hibernate might have either problems with the all capital letters of the name or with the underscore. If it is no problem for your app then stick to the Java (Beans) naming conventions, i.e. use CamelCaseNotation, starting with a lower case letter for field names, and the getter/setter methods start with get/set followed by the field name now having the first letter capitalized. Might make things easier.

CU
Froestel
 
Shariquddin Mohammed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andreas Erber,

Firstly a big thanks for showing interest and taking some time out to reply.

I tried your approach of changing the naming convention, it still does not work. Please let me know if you have any further ideas of where you might think i am going wrong.

Best,
 
Darvesh Niz
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here are some good use cases for hibernate and jpa
hope it helps
http://www.makemyinfo.com/Tutorial.do?action=first

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic