3 ms·
For the schema stuff, these days what i would do is write the objects, add the minimal set of JPA annotations (which can be as little as @Entity at the top and
by twic 13y ago
For the schema stuff, these days what i would do is write the objects, add the minimal set of JPA annotations (which can be as little as @Entity at the top and @Id on the ID column), then generate the DDL from that. You don't need any XML for the mapping.
Sadly, you do still need a persistence.xml with the database connection details, and for some providers a list of all your entity classes (WTF). I have a build script which generates all that (amongst other things), though:
https://bitbucket.org/twic/jpaquickstart/src/0c5b383026ba097f86e29866b6ccd90e9663f2fd/build.gradle?at=default https://bitbucket.org/twic/jpaquickstart/src/0c5b383026ba097...
- Nanzikambe 13y agoInteresting! I did end up using annotations as you mention. However I chose to manage the db structure myself because early on I encountered problems when I changed data types and indexes, hibernate incombination with JavaDB dropped then recreated the structure, which is fine, but then if you want to push your changes to the live version, I had to write the SQL to port the live data into the newly created table which was a PITA given javadb can't insert into "GENERATED ALWAYS AS IDENTITY" columns, so that in turn meant more SQL to preserve referential relationship between data. I was always left feeling I did something totally wrong in that respect, so I blame myself. A part of this also stems from the way I approach building an application, I'll always spec & then create out the DB as a way of helping me visualise the model before I start doing any "real" coding. I still respect Java enormously, but I'm not at all sold on JEE application servers for anything below enterprise scale applications. And for any case where you need a quick prototype, Java definitely will not be my choice in the future.