Hello
I have a problem with my configuration of Annotations.
with Hibernate 3.6.1, Im taying to map a Mysql 5.5 database, in a Liferay 6 Portlet
I can do de mapping with HBM files and everithing works fine, but when I try to doit with annotations I get the error:
Code:
Initial SessionFactory creation failed.org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.timestamp.database.datatypes.Freguesia.concelho references an unknown entity: com.timestamp.database.datatypes.Concelho
15:08:15,625 ERROR [PortletRequestDispatcherImpl:107] org.apache.jasper.JasperException: An exception occurred processing JSP page /view.jsp at line 19
16: List<Distrito> studentResult=null;
17: List<Categoria> categResult=null;
18: try{
19: Session sessions = HibernateUtil2.getSession();
20: sessions.beginTransaction();
21:
22: studentResult = sessions.createQuery("from Distrito").list();
The bean code is the following:
Code:
package com.timestamp.database.datatypes;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "CIOFE_FREGUESIA")
public class Freguesia
{
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer id;
@Column(name = "CODE", unique = true, length = 10)
public String code;
@Column(name = "NAME", length = 100)
public String name;
@ManyToOne
@JoinColumn(name = "ID_CONCELHO")
public Concelho concelho;
public Integer getId()
{
return id;
}
public void setId(Integer id)
{
this.id = id;
}
public String getCode()
{
return code;
}
public void setCode(String code)
{
this.code = code;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public Concelho getConcelho()
{
return concelho;
}
public void setConcelho(Concelho concelho)
{
this.concelho = concelho;
}
}
Code:
package com.timestamp.database.datatypes;
import java.util.Vector;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Entity;
@Entity
@Table(name = "CIOFE_CONCELHO")
public class Concelho
{
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer id;
@Column(name = "CODE", length = 10)
public String code;
@Column(name = "NAME", length = 100)
public String name;
@ManyToOne
@JoinColumn(name = "ID_DISTRITO")
public Distrito myDistrito;
public Integer getId()
{
return id;
}
public void setId(Integer id)
{
this.id = id;
}
public String getCode()
{
return code;
}
public void setCode(String code)
{
this.code = code;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public Distrito getMyDistrito()
{
return myDistrito;
}
public void setMyDistrito(Distrito myDistrito)
{
this.myDistrito = myDistrito;
}
public Vector getMyFreguesia()
{
return myFreguesia;
}
public void setMyFreguesia(Vector myFreguesia)
{
this.myFreguesia = myFreguesia;
}
/**
*
* @element-type Freguesia
*/
public Vector myFreguesia;
}
the configuration is the following (I have some part of it commented so I can switch from annotations to HBM files)
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/lportal</property>
<property name="hibernate.connection.username">lportal</property>
<property name="hibernate.connection.password">lportal</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">validate</property>
<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>
<mapping package="com.timestamp.database.datatypes"/>
<mapping class="com.timestamp.database.datatypes.Avaliacao"/>
<mapping class="com.timestamp.database.datatypes.Categoria"/>
<mapping class="com.timestamp.database.datatypes.Concelho"/>
<mapping class="com.timestamp.database.datatypes.Distrito"/>
<mapping class="com.timestamp.database.datatypes.EmailEnviado"/>
<mapping class="com.timestamp.database.datatypes.Emprego"/>
<mapping class="com.timestamp.database.datatypes.EntidadeExterna"/>
<mapping class="com.timestamp.database.datatypes.Especialidade"/>
<mapping class="com.timestamp.database.datatypes.EstadoCivil"/>
<mapping class="com.timestamp.database.datatypes.EstadoPedido"/>
<mapping class="com.timestamp.database.datatypes.Ficheiro"/>
<mapping class="com.timestamp.database.datatypes.Formacao"/>
<mapping class="com.timestamp.database.datatypes.Freguesia"/>
<mapping class="com.timestamp.database.datatypes.Habilitacao"/>
<mapping class="com.timestamp.database.datatypes.Inscrito"/>
<mapping class="com.timestamp.database.datatypes.PedidoServico"/>
<mapping class="com.timestamp.database.datatypes.PedidoServicoCampos"/>
<mapping class="com.timestamp.database.datatypes.Ramo"/>
<mapping class="com.timestamp.database.datatypes.TipoEmprego"/>
<mapping class="com.timestamp.database.datatypes.TipoEntidade"/>
<mapping class="com.timestamp.database.datatypes.TipoFicheiro"/>
<mapping class="com.timestamp.database.datatypes.TipoFormacao"/>
<mapping class="com.timestamp.database.datatypes.TipoHabilitacao"/>
<mapping class="com.timestamp.database.datatypes.TipoHabilitacaoEmprego"/>
<mapping class="com.timestamp.database.datatypes.TipoServico"/>
<mapping class="com.timestamp.database.datatypes.TipoServicoCampos"/>
<mapping class="com.timestamp.database.datatypes.Unidade"/>
<!-- <mapping resource="com/timestamp/database/hbm/Avaliacao.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/Categoria.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/Concelho.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/Distrito.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/EmailEnviado.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/Emprego.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/EntidadeExterna.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/Especialidade.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/EstadoCivil.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/EstadoPedido.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/Ficheiro.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/Formacao.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/Freguesia.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/Habilitacao.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/Inscrito.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/PedidoServico.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/PedidoServicoCampos.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/Ramo.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/TipoEmprego.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/TipoEntidade.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/TipoFicheiro.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/TipoFormacao.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/TipoHabilitacao.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/TipoHabilitacaoEmprego.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/TipoServico.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/TipoServicoCampos.hbm.xml"/>
<mapping resource="com/timestamp/database/hbm/Unidade.hbm.xml"/>-->
</session-factory>
</hibernate-configuration>
and the HBM files are the following
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.timestamp.database.datatypes">
<class name="Concelho" table="CIOFE_CONCELHO">
<id name="id" column="ID">
<generator class="native"/>
</id>
<property name="code" column="CODE" length="10"/>
<property name="name" column="NAME" length="100"/>
<many-to-one name="myDistrito"
column="ID_DISTRITO"
class="Distrito" />
</class>
</hibernate-mapping>
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.timestamp.database.datatypes">
<class name="Freguesia" table="CIOFE_FREGUESIA">
<id name="id" column="ID">
<generator class="native"/>
</id>
<property name="code" column="CODE" length="10"/>
<property name="name" column="NAME" length="100"/>
<many-to-one name="concelho"
column="ID_CONCELHO"
class="Concelho" />
</class>
</hibernate-mapping>
Im really lost here, because I really whanted do use anotations but had to switch to hbm beacause I was stuck
Thanks for the help