These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Composite Id
PostPosted: Tue Jan 12, 2010 12:31 pm 
Newbie

Joined: Wed Jan 17, 2007 9:39 pm
Posts: 5
Hi,

I'm having trouble mapping a class with a composite id. I don't know why, but when I try to open a hibernate session it throws a NullPointerException.

Here's the code:
Code:
@Entity
@Table(name = "bo_users")
public class Users implements Serializable {

   @Id
   @Column(length = 20, nullable = false)
   private String username;
   @Column(length = 20, nullable = false)
   private String password;
   @OneToMany
   private List<MonitoredUsers> monitoredUsers;
}

@Embeddable
public class MonitoredUsersPk implements Serializable {
   @ManyToOne
   private Users user;
   private String monitoredUser;
}

@Entity
@Table(name = "bo_monitored_users")
public class MonitoredUsers implements Serializable {

   @Id
   private MonitoredUsersPk pk;
}


Here's the sessionFactory:
Code:
static {
      try {

         sessionFactory = new AnnotationConfiguration().
            setProperty("hibernate.session_factory_name", "BOConnection").
            setProperty("hibernate.hbm2ddl.auto", "update").
            setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect").
            setProperty("hibernate.show_sql", "false").
            setProperty("hibernate.order_updates", "true").
            setProperty("hibernate.cglib.use_reflection_optimizer", "true").
            setProperty("hibernate.connection.driver_class", "com.microsoft.sqlserver.jdbc.SQLServerDriver").
            setProperty("hibernate.connection.url", "jdbc:sqlserver://localhost\SQLEXPRESS;integratedSecurity=true").
            setProperty("hibernate.connection.autocommit", "false").
            setProperty("hibernate.c3p0.min_size", "0").
            setProperty("hibernate.c3p0.max_size", "100").
            setProperty("hibernate.c3p0.timeout", "60").
            setProperty("hibernate.c3p0.max_statements", "0").
            addAnnotatedClass(Users.class).
            addAnnotatedClass(MonitoredUsersPk.class).
            addAnnotatedClass(MonitoredUsers.class).
            buildSessionFactory();
      } catch (Throwable ex) {
         throw new ExceptionInInitializerError(ex);
      }
   }

And the stack trace when I call openSession:

Code:
java.lang.ExceptionInInitializerError
   at br.com.cedro.database.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:57)
   at br.com.cedro.config.InitListener.contextInitialized(InitListener.java:87)
   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
   at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
   at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
   at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
   at org.apache.catalina.core.StandardService.start(StandardService.java:516)
   at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
   at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
   at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.NullPointerException
   at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:416)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:309)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1319)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
   at br.com.cedro.database.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:55)
   ... 16 more


I really don't know what I'm doing wrong.

I'm using hibernate 3.2 and hibernate annotations 3.3.

Thanks for helping.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.