7 Replies Latest reply on Sep 16, 2008 4:39 AM by Chris Hembrow

    JBoss 4.2.0, hibernate annotations being picked up

    Chris Hembrow Newbie


      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

       <mbean code="org.jboss.hibernate.jmx.Hibernate"
       <attribute name="DatasourceName">java:/DefaultDS</attribute>
       <attribute name="Dialect">
       <attribute name="SessionFactoryName">
       <attribute name="CacheProviderClass">
       <attribute name="ShowSqlEnabled">true</attribute>

      and an example entity looks like
      @Table( name="NETWORKS" )
      @NamedQuery( name="getNetworks", query="from Network" )
      public class Network {
       private Long id;
       private String name;
       private Country country;
       @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="NETWORKS_PK_SEQ")
       public Long getId() {
       return id;
       public void setId( Long _id ) {
       id = _id;
       @ManyToOne( fetch=FetchType.LAZY )
       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,