Eclipse in Styleby Daniel Spiewak
Beyond development, beyond usage

An Easier Java ORM Part 4

Posted by Daniel Spiewak on July 30th, 2007
Categories: Java
Tags: , , ,

Moved to: http://www.codecommit.com/blog/java/an-easier-java-orm-part-4

Add to DZone

5 Responses to “An Easier Java ORM Part 4”

  1. David Marko Says:

    Very nice. I really look forward details on initial migration features in trunk version. How it can be used/tested? Please give some brief details. I have compiled version from trunk so I can test.

    Also its a bit off-topic, how @ManyToMany scenario is supposed to beeing used? U have User and Role tables and need ManyToMany relationship between them. How to setup it?

    Thanks,
    David

  2. Daniel Spiewak Says:

    The new migration code will work the same way as the old generating code. So, you would call the EntityManager#migrate(Class̷ ;) method. This would handle all of the migration tasks (including diffing the existing schema, and CREATE/ALTER/DROP to match the new one). There’s an Ant task which doesn’t work (at least, I don’t think it does), and command line invocation is also supported.

    Good question with the relationship annotations. I’ll dash off a quick article today explaining how they work, as well as the @Ignore annotation, which I just realized I forgot to mention in today’s post.

  3. Daniel Spiewak Says:

    Argg, WordPress ate my comment. Suffice it to say, it’s the “migrate” method within EntityManager. :-)

  4. David Marko Says:

    Just used ActiveObjects from trunk and tried migration feature. On firt run AO created a new table correctly. Then I changed a JAVA class(add some additional property) and called migrate once again. This is what a go :( subdomain is a JAVA bean a store in database)

    org.postgresql.util.PSQLException: ERROR: relation “subdomain” already exists
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:15 8)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1316)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:191)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:337)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:283)
    at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:2 8)
    at net.java.ao.schema.Generator.migrate(Generator.java:150)
    at net.java.ao.EntityManager.migrate(EntityManager.java:143)

  5. Daniel Spiewak Says:

    Yeah, I would expect that. Right now in trunk/ the migrations feature isn’t fully wired up. I haven’t actually written the “glue code” to connect the migrate() method to the schema reading and diffing features. In other words, it’s trying to create the schema all over again each time you call the method. :-S

Leave a Reply