tmpsa (16) [Avatar] Offline
#1
Is is possible to retrieve the configuration, such as table and column name, from a JPA entity? Let's say that you want to write a method to build a String containing a standard SQL INSERT statement that creates the entity in some other database. You could hard-code the names, but it would be much nicer to get them from the entity.

Is that possible?
reza_rahman (456) [Avatar] Offline
#2
Re: Get JPA configuration from an entity
Per,

It isn't possible today, but will be possible in JPA 2 using the meta-data API. The best you can do today is use refection (annotations) or XML parsing (persistence.xml) yourself. Too time intensive and complicated, unless you really need it smilie.

Unfortunately, I don't know any provider specific features that allow you to do this today either.

Cheers,
Reza
tmpsa (16) [Avatar] Offline
#3
Re: Get JPA configuration from an entity
Aha, very interesting! That will be one more reason that I impatiently wait for JPA 2. (I also desperately need the Criteria functions that have been around in Hibernate for some time).

So for now, it's hard-coding the names, and replace all that when JPA 2 arrives.

Thanks for sharing the knowledge!
Per
tmpsa (16) [Avatar] Offline
#4
Re: Get JPA configuration from an entity
Speaking of JPA 2...
Will there be a new edition of your excellent book teaching these latest and greatest improvements?
reza_rahman (456) [Avatar] Offline
#5
Re: Get JPA configuration from an entity
Per,

I have a real desire to write the second edition and Manning has been willing too. The problem is that I now have more than my hands full.

I feel obligated to continue to support readers in any ways possible, I work inside the JCP EGs and I now lead Resin's EJB 3.1 Lite container. In the coming months, I am working on a project that is essentially a Spring plugin to turn any Spring 2.5 application into a running Java EE 6 (EJB 3.1 Lite) container and port some of the more popular/well-used Spring APIs to JSR 299 (Contexts and Dependency Injection for Java EE).

My other authors seem busy at the moment too. Truth be told, I really could use a co-author for EJB 3 in Action or Head First EJB to cover EJB 3.1 and JSR 299. If you know of anyone, please feel free to have them contact me. All my contact info is on my website...

Cheers,
Reza

PS: If I might ask a favor would you be kind enough to leave Amazon feedback on the book? It really helps the book out and any potential readers too...