[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - JBoss 4.2.0, hibernate annotations being picked up

pixel do-not-reply at jboss.com
Fri Mar 7 10:27:42 EST 2008


Hi,

I am trying to set up a new project using hibernate annotations instead of mapping files.  I am running JBoss 4.2.0-GA.

My hibernate-service.xml looks like

  | <server>
  |         <mbean code="org.jboss.hibernate.jmx.Hibernate"
  |                 name="jboss.har:service=HibernateHCE">
  |                 <attribute name="DatasourceName">java:/DefaultDS</attribute>
  |                 <attribute name="Dialect">
  |                         org.hibernate.dialect.OracleDialect
  |                 </attribute>
  |                 <attribute name="SessionFactoryName">
  |                         java:/hibernate/SessionFactory
  |                 </attribute>
  |                 <attribute name="CacheProviderClass">
  |                         org.hibernate.cache.HashtableCacheProvider
  |                 </attribute>
  |                 <attribute name="ShowSqlEnabled">true</attribute>
  |         </mbean>
  | </server>
  | 

and an example entity looks like

  | @Entity
  | @Table( name="NETWORKS" )
  | @NamedQuery( name="getNetworks", query="from Network" )
  | public class Network {
  | 
  | 	private Long id;
  | 	private String name;
  | 	private Country country;
  | 
  | 	@Id
  | 	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="NETWORKS_PK_SEQ")
  | 	@Column(name="PK_NETWORK_ID")
  | 	public Long getId() {
  | 		return id;
  | 	}
  | 	public void setId( Long _id ) {
  | 		id = _id;
  | 	}
  | 	
  | 	
  | 	@ManyToOne( fetch=FetchType.LAZY )
  | 	@Column(name="FK_COUNTRY_ID")
  | 	public Country getCountry() {
  | 		return country;
  | 	}
  | 	void setCountry( Country _country ) {
  | 		country = _country;
  | 	}
  | 	
  | 
  | 	@Column(name="NETWORK_NAME", unique=true)
  | 	public String getName() {
  | 		return name;
  | 	}
  | 	void setName( String _name ) {
  | 		name = _name;
  | 	}
  | 
  | }
  | 

I am getting the session factory by 
(SessionFactory) new InitialContext().lookup( "java:/hibernate/SessionFactory" );

But it doesn't appear to be seeing the annotated files.  Running session.createQuery( "from Network" ).list() gives Network is not mapped [from Network] ???

Am I missing something?  I found a reference to using 
new AnnotationConfiguration().buildSessionFactory() - but isn't it better to get the factory from the lookup?




Thanks in advance,

pixel



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4134876#4134876

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4134876



More information about the jboss-user mailing list