-->
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.  [ 1 post ] 
Author Message
 Post subject: Incorrect number of related entities after annotating
PostPosted: Tue Dec 05, 2006 3:59 pm 
Newbie

Joined: Thu Mar 24, 2005 2:17 pm
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
Core - 3.2.1, Nootations - 3.2.0

Mapping documents:

<hibernate-mapping>
<class name="com.core.model.domain.activity.Activity"
table="activity">

<id name="oid" column="c_oid" access="field" type="oid">
<generator class="com.db.model.orm.DbObjectIdGenerator"/>
</id>

<property name="name" column="c_name" access="field" not-null="true"/>
<set name="requiredSkills" table="reqskill" access="field" lazy="false" >
<key>
<column name="c_activity" not-null="true" />
</key>
<many-to-many
class="com.core.model.domain.activity.PersonSkill"
column="c_skill"
fetch="join"/>
</set>

</class>
</hibernate-mapping>


Name and version of the database you are using:
HSQLDB 1.8.0

I have a Activity which can have a set of requiredSkills. The table layout is :
create table ACTIVITY (
C_OID varchar(32) not null,
C_NAME varchar(255) not null,
primary key (C_OID)
);

create table SKILL (
C_OID varchar(32) not null,
C_NAME varchar(255) not null,
primary key (C_OID)
);

create table REQSKILL (
C_ACTIVITY varchar(32) not null,
C_SKILL varchar(32) not null,
primary key (C_ACTIVITY, C_SKILL)
);

alter table REQSKILL
add constraint FK69B66AF
foreign key (C_ACTIVITY)
references ACTIVITY;

alter table REQSKILL
add constraint FK69B66AF9
foreign key (C_SKILL)
references SKILL;

I am trying to annotate the Activity domain object. With the hbm mapping file as listed above I get the correct number of objects. But when I annotate Activity.java I get the incorrect number.

I have the following data
Activity:
<activity C_OID="100sda" C_NAME="Water painting" />
<activity C_OID="100saa" C_NAME="Tile replacing" />

Skill:
<skill C_OID="100a" C_NAME="Water Painting" />
<skill C_OID="100b" C_NAME="Oil Painting" />
<skill C_OID="100c" C_NAME="Removing Tile" />
<skill C_OID="100d" C_NAME="Placing tile" />
<skill C_OID="100e" C_NAME="Drawing" />

reqskill:
<reqskill C_ACTIVITY="100sda" C_SKILL="100e" />
<reqskill C_ACTIVITY="100sda" C_SKILL="100a" />
<reqskill C_ACTIVITY="100saa" C_SKILL="100c" />
<reqskill C_ACTIVITY="100saa" C_SKILL="100d" />

If i query for a single Activity by oid i get the correct Activity. But when I try to retrieve all i am expecting two activities (one corresponding to "Water painting" and the other for "Tile replacing") with two required skills each.

But, I am getting four activities. Two for "Water Painting" and two for "Tile replacing" and my tests are failing.

My Annotated class looks like this
@Entity
@Table(name="ACTIVITY")
public class Activity implements Serializable
{
@Id
@GeneratedValue(generator = "tt-oid")
@GenericGenerator(name = "tt-oid", strategy = "com.db.model.orm.DbObjectIdGenerator")
@AccessType("field")
@Column(name = "C_OID", nullable = false)
private String oid;

@AccessType("field")
@Column(name = "C_NAME", nullable = false, unique = true)
private String name;

@OneToMany(fetch = FetchType.EAGER)
@JoinTable(name = "REQSKILL", joinColumns = { @JoinColumn(name = "C_ACTIVITY") }, inverseJoinColumns = @JoinColumn(name = "C_SKILL"))
private Set<PersonSkill> requiredSkills;

... (getters and setters)
}

@Entity
@Table(name = "skill")
public class PersonSkill implements Serializable
{
@Id
@GeneratedValue(generator = "tt-oid")
@GenericGenerator(name = "tt-oid", strategy = "com.db.model.orm.DbObjectIdGenerator")
@AccessType("field")
@Column(name = "C_OID", nullable = false)
private String oid;

@AccessType("field")
@Column(name = "C_NAME", unique=true, nullable=false)
private String name;

... (getters and setters)
}

Have seen examples in the documentation and seems like i am doing the Set mapping correctly but for some reason it is not correct. Using just the hibernate mapping file obviously works fine and the tests succeed but not when the objects are annotated.

Has anybody else seen this? Am I missing something? If someone could point me in the right direction ..

Thx!


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

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.