File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes  Column appears twice - Hibernate generated prepared statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark " Column appears twice - Hibernate generated prepared statement" Watch " Column appears twice - Hibernate generated prepared statement" New topic
Author

Column appears twice - Hibernate generated prepared statement

Ally Cavs
Ranch Hand

Joined: Aug 25, 2008
Posts: 89
Hi,

Here are my hibernate mappings:




The error I get is that Hibernate generates the following prepared statement:
insert into MEDIA (PERSON_ID, FILE_TYPE, FILE_LOCATION, ORDER_NUM, TITLE, person_id, file_id) values (?, ?, ?, ?, ?, ?, ?)
Notice how PERSON_ID appears twice

I changed it so PERSON_ID to be upper case in all places. Hibernate just falls over at the point of loading its XML files then.
i tried insert="false". Hibernate does not like this either. In fact I get a message before I even compile
Attribute "insert" must be declared for element type "one-to- many".

I am using Hibernate 3.3.1
Please help I have this error for the last few days and no matter what i do I cant fix it

Thanks
Ally Cavs
Ranch Hand

Joined: Aug 25, 2008
Posts: 89
<property name="person_id" column="PERSON_ID" type="string" insert="true" update="true"/>

in <class name="ie.gymlockr.admin.details.UploadedFile" table="MEDIA">
works
?
can someone explain what insert="true" update="true" do?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Ally Cavs wrote:<property name="person_id" column="PERSON_ID" type="string" insert="true" update="true"/>

in <class name="ie.gymlockr.admin.details.UploadedFile" table="MEDIA">
works
?
can someone explain what insert="true" update="true" do?


Ok, so for simplicity lets say I have an object

public class Person

with two properties

private Parent father
private int fatherId

Now both properties are the same relationship in the database, but I have both of those because of lets say legacy code already calls person.getFatherId()

but I want all my new code to call person.getFather().getFatherId();

and for Hibernate I need to store the fatherId into the person table. Well I don't want both associations to try and update the same FK field in the person table, so I have to state that one of the mapped properties be updatable="false" so hibernate does not include it in the update statement. Because it shouldn't show up in the update statement twice. Once for the fatherId property and once for the father associated Parent object.

The same thing happens with insertable="false" you are saying in insert statements not to include it.

Hope that helps clear things up

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
Consider Paul's rocket mass heater.
 
subject: Column appears twice - Hibernate generated prepared statement