I have an abstract 'folder' class with the following annotations
@Entity
@Table(name="folder")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
name="foldertype",
length=50,
discriminatorType=DiscriminatorType.STRING
)
@DiscriminatorValue("f")
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();
hsession.saveOrUpdate(r);
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();
yearFolder.setYear(year);
yearFolder.setRootFolder(rootFolder);
rootFolder.addYearFolder(yearFolder);
hsession.save(rootFolder);
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