Hibernate Annotations doesnt work if i dont declare the mapping class
sogukk Mar 28, 2010 10:54 AMHello,
My problem is ,my hibernate annotations doesnt work(says unknown entity) if
i dont define the entity classes in the hibernate.cfg.xml file with putting
a line like
"<mapping class="domain.view.MenuCategory"></mapping>".
What can i do to fully get use of annotations?
My components.xml file has the following lines.
<persistence:hibernate-session-factory name="hibernateSessionFactory" />
<persistence:managed-hibernate-session name="sessionHibernate" auto-create="true" session-factory-jndi-name="myfactory"/>
And this is my hibernatecfg.xml file.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="myfactory">
<property name="current_session_context_class">thread</property>
<propertyname="hibernate.bytecode.use_reflection_optimizer">false</property><property name="show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/testdatasource</property>
<property name="hibernate.format_sql">true</property>
<property name="hbm2dll.auto">create-drop</property>
<property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="transaction.flush.before_completion">true</property>
<property name="connection.release_mode">after_statement</property>
</session-factory>
</hibernate-configuration>
And my context.xml files is as follows.
<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/testdatasource" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/hacivad"/>
</Context>
and the class is,
package domain.view;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@SuppressWarnings("serial")
@Entity
@Table(name = "VIEW_MENU_CATEGORY")
public class MenuCategory implements Serializable {
@Id
@Column(name = "ID")
private Long id;
@Column(name = "CATEGORY_LABEL")
private String label;
@Column(name = "KEY")
private String key;
public Long getId() {
return id;
}
public String getLabel() {
return label;
}
public String getKey() {
return key;
}
}
thanks for the help.
My problem is ,my hibernate annotations doesnt work(says unknown entity) if
i dont define the entity classes in the hibernate.cfg.xml file with putting
a line like
"<mapping class="domain.view.MenuCategory"></mapping>".
What can i do to fully get use of annotations?
My components.xml file has the following lines.
<persistence:hibernate-session-factory name="hibernateSessionFactory" />
<persistence:managed-hibernate-session name="sessionHibernate" auto-create="true" session-factory-jndi-name="myfactory"/>
And this is my hibernatecfg.xml file.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="myfactory">
<property name="current_session_context_class">thread</property>
<propertyname="hibernate.bytecode.use_reflection_optimizer">false</property><property name="show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/testdatasource</property>
<property name="hibernate.format_sql">true</property>
<property name="hbm2dll.auto">create-drop</property>
<property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="transaction.flush.before_completion">true</property>
<property name="connection.release_mode">after_statement</property>
</session-factory>
</hibernate-configuration>
And my context.xml files is as follows.
<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/testdatasource" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/hacivad"/>
</Context>
and the class is,
package domain.view;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@SuppressWarnings("serial")
@Entity
@Table(name = "VIEW_MENU_CATEGORY")
public class MenuCategory implements Serializable {
@Id
@Column(name = "ID")
private Long id;
@Column(name = "CATEGORY_LABEL")
private String label;
@Column(name = "KEY")
private String key;
public Long getId() {
return id;
}
public String getLabel() {
return label;
}
public String getKey() {
return key;
}
}
thanks for the help.