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)
|