Quote:
Are you writing java code first, and then hbm.xml...
or are you just as comfortable with defining the hbm.xml first and then have it generate java code ?
I'm comfortable either way. My only concern was if I needed to add methods to the class, something like:
addFoo(foo) { foos.add(foo); foo.setParent(this); }
then I wouldn't want to regenerate and lose that, but it seems like you could sub-class the generated class to add functionality.
------------
Let me backup and explain what I'm working with here. Any suggestions are welcome, like I said I'm new to java (and stored procedures!) and kind of figuring this out as I go.
I'm working with an Oracle guy who is building the database and prefers to use stored procedures for all insert/update/delete operations so he can perform other tasks behind the scenes (logging, auditing, etc). Also, most of the business logic, calculations will happen on the database side.
What I was hoping to do is parse that PROCEDURE definition into an .hbm file, then use hbm2java to build the persistent class and other classes. Sounds like hbm2java might do the trick, I'll look into it some more.
------------
Here's a rundown of how my stored procedure persister works. If this is a rediculously stupid hack, I'm all ears for better methods!
1. CustomTransactionFactory returns CustomTransaction
a. CustomTransaction generates a transactionId for this logical set of actions
2. CustomPersister extends EntityPersister, overrides:
insert(Object[] values, Object object, SessionImplementor session)
a. I also use a CustomIdentifierGenerator to return null so that inserts go through this insert method since Id's are generated by the stored procedure.
3. insert() gets the transactionId from the session's transaction and translates the Object array into a Map of value by property name
a. call abstract method: doInsert(transactionId, myPropsMap, session.connection());
4. doInsert is implemented for each persistent type. It extracts the values from the Map and calls MyTypeProcedures.insert(transactionId, [all properties], connection). I did this so that this method doesn't depend at all on Hibernate, it's just a static method that calls a stored procedure with the supplied arguments.
5. MyTypeProcedures.insert creates and executes a CallableStatement, returns the inserted Id
6. doInsert() returns the Id back to insert()
7. insert() returns (Serializable) Id
That's it... I've simplified and left out a few steps here. There's also a subTransactionId that gets passed back with the inserted Id and set on the persistent object (using update="false" in mapping file so that doesn't trigger an update)
Hope that all makes some kind of sense
- Ryan