Fog Creek Software
Discussion Board




auto generating java code from sql database

In the last few months, I've been doing a lot of coding that uses xml schemas. I develop the schemas in xmlspy and then generate java code using jaxb.  It's working really well ... my productivity has substantially increased.

The stuff I spend a lot of time on still is the database->java coding.  Which got me thinking...are there any good tools that you can point at a relational database design and auto-generate java code that knows how to read and write into those database tables? 

I know XDoclet will go from code to sql/xml, but I don't know of any tools that go the other direction.

j b
Thursday, October 30, 2003

Apple's Java-WebObjects framework does this in its EOModeler application, but that requries you use the (pretty good) WebObjects app framework.

H. Lally Singh
Thursday, October 30, 2003

Take a look at hibernate

tester
Thursday, October 30, 2003

I second Hibernate. 

I maintain a bunch of hand coded JDBC for one application and Hibernate in another application.  The Hibernate application is far easier to change and maintain.

Joe Blandy
Thursday, October 30, 2003

Hibernate does seem pretty cool. I was a little disapointed that it extends sql, rather than just using standard sql. Is there a good reason for this? Also, is it usable in non-EJB environments?

j b
Thursday, October 30, 2003

> Also, is it usable in non-EJB environments?

I don't have any ejbs in my environment and it works great!

Joe Blandy
Thursday, October 30, 2003

Quiz: Is there a programming language that is programmable?

And you thought all turning complete programming languages are created equal.....

Mac
Thursday, October 30, 2003

The point of Hibernate and other similar tools (Toplink, JDO implementations) is that you don't have to deal with SQL.

But isn't this not going in the direction the original asked about? Tables (SQL) -> Java. I suspect it's a lot easier to use an OR-mapping tool like Hibernate if you start from the object model and let the tool create the data model.

Walter Rumsby
Thursday, October 30, 2003

Hmm,

There's something over at TheServerSide.com about turning PL/SQL into Java.

http://www.theserverside.com/home/thread.jsp?thread_id=22126

Walter Rumsby
Friday, October 31, 2003

re: PL/SQL, that's quite interesting but doesn't help me (my database is mysql, not oracle).
The reason I'm so insistent on going from sql->java rather than the other way 'round twofold:
1)The database layer often survives long after the original application is gone. Other applications or the application that succeeds mine may inherit it. So getting that right is pretty key.
2)Visual design tools for relational databases exist in abundance.

I need to play around with Hibernate some. I don't think it's what I was asking for, but it seems like the sort of thing that might come in useful.

j b
Friday, October 31, 2003

from the hibernate website ...

Development Process
Any of the following development scenarios are supported:

top-down
***

bottom-up
start with an existing data model
use Middlegen to generate the mapping document
use the hbm2java tool to generate skeletal Java code
fill in the business logic by hand

j b
Friday, October 31, 2003

I believe Jakarta Torque (was/is part of Turbine) has the capability to pull the table structure out of a database and then generate a bunch of code which provides the O-R mapping so you can then do:

Customer c = new Customer();
c.setFirstname("Joe");
c.setLastname("Bloggs");
c.save();

I haven't used it for that purpose, only for setting out database structure then letting it make the 'CREATE TABLE...' etc SQL, run that in the database, and giving me java classes to then use that data structure.

Konrad
Friday, October 31, 2003

Someone else I talked to in a bar last night mentioned toplink. It belongs to oracle now, so I don't imagine it works to well with mysql anymore, however...

j b
Saturday, November 01, 2003

*  Recent Topics

*  Fog Creek Home