• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Column appears twice - Hibernate generated prepared statement

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<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?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic