I have problem with @ManyToOne which generate that exception:
Code:
Caused by: org.hibernate.MappingException: Could not determine type for: pl.diagno.model.vo.City, for columns: [org.hibernate.mapping.Column(city)]
In Person is reference to City. When I remove this reference, it works.
I put in a lot of time reading many threads and finding solution but the most similar case is here:
http://forum.springsource.org/showthread.php?t=86745But there the problem was in the lack of some setters.
Code:
package pl.diagno.model.vo;
import java.util.Date;
import javax.persistence.*;
@Entity
public class Person {
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
private long id;
private String name;
private String surname;
private City city;
public Person(){}
public Person(String name, String surname, City city){
this.name=name;
this.surname=surname;
this.city=city;
}
@Column
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Column
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
@Column
@ManyToOne(cascade = CascadeType.ALL, targetEntity = City.class)
@JoinColumn(name="city_id")
public City getCity() {
return city;
}
public void setCity(City city) {
this.city = city;
}
}
Code:
package pl.diagno.model.vo;
import javax.persistence.*;
@Entity
public class City {
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
private long id;
private String name;
public City(){}
public City(String name){
this.name=name;
}
@Column
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Column
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>pl.diagno.model.vo.City</value>
<value>pl.diagno.model.vo.Person</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</prop>
<prop key="hibernate.connection.url">jdbc:oracle:thin:@xxx-90ac33161e0:1521:XE</prop>
<prop key="hibernate.connection.username">diagno</prop>
<prop key="hibernate.connection.password">1234</prop>
<prop key="hibernate.default_schema">diagno</prop>
<prop key="hibernate.connection.pool_size">10</prop>
<prop key="show_sql">true</prop>
<prop key="dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
</props>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@xxx-90ac33161e0:1521:XE" />
<property name="username" value="diagno" />
<property name="password" value="1234" />
</bean>
</beans>
Code:
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { "applicationContext.xml" });
}
Help appreciated!