-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: USing Hbm.xml & annotations simultaneously
PostPosted: Mon Apr 04, 2005 11:31 am 
Newbie

Joined: Fri Mar 18, 2005 7:58 am
Posts: 8
Hibernate version:3.0

Hi
I am using the hbm.xml files & annotations simultaneously.I have a child collection which can have a set of child objects.The association is unidirectional & one to many(parent child).
While saving the foreign key(primary key of collection ) is not saved in child table. Can anyone please let me know where I am going wrong??

Thanks In Advance.
[b]Mapping documents:
<hibernate-mapping>
<class name="ChildImpl" table="CHILD">
<id name="id" column="CID" >
<generator class="native"/>
</id>
<property name="collectionId"/>
<property name="childObjectId"/>
<!--NOTE::We cannot use order as a property name-->
<property name="proporder"/>

<map name="childProps" table="PROPERTY" lazy="false">
<key column="CID"/>
<index column="key1" type="string"/>
<element type="string" column="value"></element>

</map>
</class>
</hibernate-mapping>


[b]
@Entity(access=AccessType.PROPERTY)
@Table(name="CHILDCOLLECTION")
public class ChildCollectionImpl {
private long id;
private Set childs = new HashSet();

@Id(generate=GeneratorType.IDENTITY)
@Column(name ="CCID")
public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

@OneToMany(cascade = CascadeType.ALL,targetEntity="ChildImpl",fetch = FetchType.EAGER)
@JoinColumn(name="CCID",nullable = false)
public Set getChilds() {
return childs;
}

public void setChilds(Set childs) {
this.childs = childs;
}


}


Following are the queries:
Hibernate: insert into CHILDCOLLECTION default values
Hibernate: insert into CHILD (collectionId, childObjectId, proporder) values (?, ?, ?)


StackTrace:
- Cannot insert the value NULL into column 'CCID', table 'Prepopulated.dbo.CHILD'; column does not allow nulls. INSERT fails.
org.hibernate.exception.ConstraintViolationException: could not insert: [ChildImpl]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 12:02 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you need bidirectionnal association

set a many-to-one association and add isInverse=true in the collection

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 05, 2005 1:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This will be doable in the next annotation release. Bidir was mandatory by the spec, it's not anymore.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.