• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unidirectional one-to-many problem

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, i am using hibernate 3. I have two classes Opportunity & Project. The mapping files are :
<hibernate-mapping>
<class name="com.msdw.pbefficiency.servicestracker.Opportunity" table="OPPORTUNITY">
<id name="id" column="OPPID">
<generator class="identity"/>
</id>
<property name="name" column="NAME" not-null="true"/>
<set name="projectList" cascade="save-update" >
<key column="OPPID" />
<one-to-many class="com.msdw.pbefficiency.servicestracker.Project" />
</set>
</class>
</hibernate-mapping>

and for Project it is :

<hibernate-mapping>
<class name="com.msdw.pbefficiency.servicestracker.Project" table="PROJECT">
<id name="id" column="PID">
<generator class="identity"/>
</id>
<property name="name" column="NAME" not-null="true"/>

</class>
</hibernate-mapping>

The table PROJECT has an OPPID field which is a foreign key to OPPID in OPPORTUNITY table.

jsp has :
Opportunity o = new Opportunity();
o.setName("Opp1");
Set list = new HashSet();
o.setProjectList(list);
Project p = new Project();
p.setName("P1");
list.add(p);
session.saveOpp(o);

On the method call session.save(o) I get the following error:

7 Error org/hibernate/util/JDBCExceptionReporter The column OPPID in table PROJECT does not allow null values.

This means that the OPPID field in PROJECT is not being automatically populated by the OPPID which was generated for the OPPORTUNITY table. Isn't this what is expected from hibernate automatically?

Please let me know if I am missing something here. All examples which I have seen show bi-directional i.e. with inverse=true, so all the help I can get is definitely appreciated!!
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to this section of the Hibernate reference, you have to
specify a not-null="true" in the <key> element.
 
Juzar Roopawalla
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot for your reply. the issue is resolved. somehow i overlooked that attribute...something tells me there will be many more queries to come in the very near future
 
Something about .... going for a swim. With this tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic