2 Replies Latest reply on Jun 5, 2006 2:00 PM by On Man

    Unable to get @Id @GeneratedValue to even appear to work.

    On Man Newbie

      I have an abstract 'folder' class with the following annotations


      and the following generatedValue annotation.

      @Id @GeneratedValue(strategy=GenerationType.AUTO)

      on my getId method.

      I have two subclasses of the folder class RootFolder and YearFolder.
      I continue to then create a RootFolder

      RootFolder r = new RootFolder();

      But when I look in the database the id generated is 0. So I'm not convinced that my auto generation annotation is working.

      I then go to create the YearFolder with the following code:

      Session hsession = HibernateUtil.getSessionFactory().getCurrentSession();
      RootFolder rootFolder = (RootFolder)hsession.createQuery("from Folder").list().get(0);
      YearFolder yearFolder = new YearFolder();

      but this fails as is complains that there is an id clash with the following error. (because both Ids are zero)

      a different object with the same identifier value was already associated with the session: [com.tier2.arena.domain.YearFolder#0])

      I'm using MySQL and used the appropriate Dialect in the properties file.

      Am I using GeneratedValue correctly?
      Running 4.0.3sp1 and hibernate-annotations-3.2.0.CR1