Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate annotations instead of mapping files

 
Arpit Chaudhary
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic