Hi all!
I'm using hibernate-tools to generate java code from an HSQLDB SQL script. Even when the documentation is not very detailed regarding the reverse engineering process, I've been able to do everything that I've needed until now (I'm even supporting inheritance using joined tables), since the source code is pretty understandable. Anyway, today I ran into a problem that, looking into the source code, doesn't seem solvable to me.
Before starting, please correct me if I'm assuming something wrong or if I have a misunderstanding of something.
One of my requisites of my application is that the generated pojos are suitable either for Oracle and HSQLDB. This is working fine, but I wanted to improve the ID generation, since right now I'm using just a plain @GeneratedValue annotation, which is the same that using <generator class="native" /> in a mapping file. This translates to use identity() in HSQLDB, and the default hibernate_sequence in Oracle. My idea was to use one different generator per table in Oracle, and maintain the usage of identity in HSQLDB.
In the mapping file this is trivial. <generator class="native"><param name="sequence">table_sequence</param></generator> will maintain Hibernate choosing between using identity or sequence depending on the underlying DB, and if sequence is the case, then it will use the table_sequence. If using annotations, I'd have to use @GenericGenerator, with strategy "native", and the same parameter "sequence" with value "table_sequence", and in @GeneratedValue use this generic generator. I've tested this by hand, and is working properly, both with Oracle and HSQLDB, so I think that is what I want to have generated in my pojos.
Now comes the tricky thing. I need a native strategy. I also need to set a sequence name for the case that a sequence is used by hibernate. The current code on hibernate-tools (org.hibernate.tool.EntityPOJOClass#generateAnnIdGenerator) does not allow to have both things specified at the same time. Either you set your strategy to "native", which generates a plain @GeneratedValue annotation, or set your strategy to something different from "assigned", "native", "identity", "sequence" or "org.hibernate.id.MultipleHiLoPerTableGenerator" to get a @GenericGenerator annotation where you can put your parameters. This makes me impossible to generate portable pojos.
I don't know if it is a known issue, but I wasn't able to find any reference to this in the forums. Also looking into the source code I don't see a solution.
Thanks for reading and (hopefully) answering :)
Cheers!
Rodrigo
|