views:

40

answers:

1

I have classes for entities like Customer, InternalCustomer, ExternalCustomer (with the appropriate inheritance) generated from an xml schema. I would like to use JPA (suggest specific implementation in your answer if relevant) to persist objects from these classes but I can't annotate them since they are generated and when I change the schema and regenerate, the annotations will be wiped. Can this be done without using annotations or even a persistence.xml file?

Also is there a tool in which I can provide the classes (or schema) as input and have it give me the SQL statements to create the DB (or even create it for me?). It would seem like that since I have a schema all the information it needs about creating the DB should be in there. I am not talking about creating indexes, or any tuning of the db but just creating the right tables etc.

thanks in advance

+1  A: 

You can certainly use JDO in such a situation, dynamically generating the classes, the metadata, any byte-code enhancement, and then runtime persistence, making use of the class loader where your classes have been generated in and enhanced. As per http://www.jpox.org/servlet/wiki/pages/viewpage.action?pageId=6619188

JPA doesn't have such a metadata API unfortunately.

--Andy (DataNucleus)

DataNucleus
I don't think this is what I was asking or sorry if I did not phrase it right. I do not want to persist the class with its byte code. I want to serialize instances of the class (like new InternalCustomer("Name", "Address");) into a database and then load it back. But when you do that with most JPA implementation you need to annotate the InternalCustomer class to guide the framework about how to serialize it into the DB. Of course as I said I can not annotate the class because the code is generated from a schema.
fnCzar
Why not define your code so people can understand it ? You have these 3 "generated" classes, but the only way you can persist one of those as serialised is if you have a field in an Entity that is marked as @Blob. Do you have that ? Otherwise I fail to understand what you're wanting
DataNucleus
thanks for answering anyways. Not sure if I will get any more answers here.
fnCzar