-->
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.  [ 2 posts ] 
Author Message
 Post subject: cant make one-to-many to work with hibernate3 & annotati
PostPosted: Wed Mar 23, 2005 2:52 am 
Newbie

Joined: Fri Mar 18, 2005 7:58 am
Posts: 8
Hi
I was trying out an example of one-to-many using hibernate 3.I am getting the following exception.

Hibernate version:hibernate-3.0rc1, hibernate-annotations-3.0alpha3

Following is the Source Code:
@Entity(access=AccessType.PROPERTY)
@Table(name="CHILDMANAGER")
public class ChildManagerModel {
private int id;
private int collId;
private int childId;
private Set<ChildProperty> childProps=new HashSet<ChildProperty>);

@Column(name ="CHILDID")
public int getChildId() {
return childId;
}

public void setChildId(int childId) {
this.childId = childId;
}

@Id(generate=GeneratorType.IDENTITY)
public int getId() {
return id;
}

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

public Set<ChildProperty> getChildProps() {
return childProps;
}

@OneToMany(cascade = ascadeType.ALL,targetEntity "ChildProperty")
@JoinColumn(name="cmId")
public void setChildProps(Set<ChildProperty> childProps) {
this.childProps = childProps;
}

@Column(name="COLLID")
public int getCollId() {
return collId;
}

public void setCollId(int collId) {
this.collId = collId;
}
}

---------------------------------------------------------------------------------
@Entity()
@Table(name="CHILDPROPERTY")
public class ChildProperty{
private int id;
private ChildManagerModel cmId;
private String key1;
private String value;

@Column(name="KEY1")
public String getKey1() {
return key1;
}

public void setKey1(String key1) {
this.key1 = key1;
}

@ManyToOne(cascade = CascadeType.ALL )
@JoinColumn(name="cmId")
public ChildManagerModel getCmId() {
return cmId;
}

public void setCmId(ChildManagerModel cmId) {
this.cmId = cmId;
}

@Id(generate = GeneratorType.IDENTITY)
public int getId() {
return id;
}

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

@Column(name="VALUE")
public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
--------------------------------------------------------------------------------------
Code for sessionFactory:
Session s = sessionFactory.openSession();
s.save(cp1);
s.save(cp2);
s.save(cm);
s.flush();
s.close();
------------------------------------------------------------------------------------
AllicationContext.xml
<beans>
<bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>com.jnetdirect.jsql.JSQLDriver</value></property>
<property name="url"><value>jdbc:JSQLConnect://IN-BELPAHAR:1121/database=Prepopulated</value></property>
<property name="username"><value>sa</value></property>
<property name="password"><value>boxmarker</value></property>
</bean>

<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalAnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="ds"/>
</property>

<property name="mappingClasses">
<list>
<value>ChildManagerModel</value>
<value>ChildProperty</value>
</list>
</property>
<!--Min these 2 properties are necessary-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
</beans>
------------------------------------------------------------
Following is the stack Trace:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in file [E:\V11\CM1\src\applicationcontext.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(childProps)]
org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(childProps)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:220)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:207)
at org.hibernate.mapping.Property.isValid(Property.java:174)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 26, 2005 5:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Annotaions has to be on the Getter and not the Setter
don't use targetEntity if you use a generic collection.
Otherwise use the fully qualified class name

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.