Thread: Which Java persistence library would you use with PostgreSQL?
Hi list, what is your choice of trust when it comes to Java persistence libraries? NetBeans gives me these out of the box: EclipseLink (JPA 2.0) Hibernate (JPA 1.0) TopLink Essentials (JPA 1.0) Is any of them known to work very well together with PostgreSQL? Or what else can you recommend? I am looking for a solution to do this (the direction is important, it's not the other way around): XML-Schema --[via Hyperjaxb3]--> annotated Java classes --[via JPA]--> PostgreSQL I've already managed to do the first two steps but would appreciate your advice on the last step. I've done loads of tutorials. This one http://bit.ly/b7vCkF for example employs Hibernate and the cool thing is that you can let the relations be created for you automatically. But it uses Apache Derby as the database backend. This is not what I want. I want to use PostgreSQL. But when exchanging Derby for PostgreSQL relations won't be created automatically anymore. Has anyone done such magic things successfully with PostgreSQL and if so, which persistence library where you using? Thank you guys for your feedback! Regards, Bata
To be more specific: When using Hibernate+Derby then in your persistence.xml there's a line like this: <property name="hibernate.connection.url" value="jdbc:derby://localhost:1527/MySampleDb;create=true"/> If you are using PostgreSQL the line would look like this: <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/MySampleDb"/> If you add ";create=true" just as in the example above, it breaks the code and you get this as a result: org.postgresql.util.PSQLException: FATAL: database "MySampleDb;create=true" does not exist at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:471) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:112) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66) at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125) at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30) at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22) at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:32) at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24) at org.postgresql.Driver.makeConnection(Driver.java:393) at org.postgresql.Driver.connect(Driver.java:267) [...] Isn't this automatical table creation possible with PostgreSQL at all? Thanks, again! Bata On 05/02/2012 12:15 PM, Bata Degen wrote: > Hi list, > > what is your choice of trust when it comes to Java persistence libraries? > > NetBeans gives me these out of the box: > EclipseLink (JPA 2.0) > Hibernate (JPA 1.0) > TopLink Essentials (JPA 1.0) > > Is any of them known to work very well together with PostgreSQL? Or what > else can you recommend? > > I am looking for a solution to do this (the direction is important, it's > not the other way around): > XML-Schema --[via Hyperjaxb3]--> annotated Java classes --[via JPA]--> > PostgreSQL > > I've already managed to do the first two steps but would appreciate your > advice on the last step. I've done loads of tutorials. This one > http://bit.ly/b7vCkF for example employs Hibernate and the cool thing is > that you can let the relations be created for you automatically. But it > uses Apache Derby as the database backend. This is not what I want. I > want to use PostgreSQL. But when exchanging Derby for PostgreSQL > relations won't be created automatically anymore. > > Has anyone done such magic things successfully with PostgreSQL and if > so, which persistence library where you using? > > Thank you guys for your feedback! > > Regards, > Bata >
> <property name="hibernate.connection.url" > value="jdbc:postgresql://localhost:5432/MySampleDb"/> > > If you add ";create=true" just as in the example above, it breaks the code > and you get this as a result: > > org.postgresql.util.PSQLException: FATAL: database "MySampleDb;create=true" > does not exist "create=true" is a Derby specific instruction to create the database if it is missing., it means nothing to the Postgres driver which rightly assumes it is the name of the database you are trying to connect to. To create tables using Hibernate you need to set up your Hibernate config to create the schema for you. The Hibernate docs will give you more information - for 3.x have a look at http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/session-configuration.html#configuration-optional. If that doesn't help, maybe the Hibernate user group is better placed to give you more information? - Sumit
Hello, I suggest You to use Hibernate. Hibernate has many ways to optimize or fix some situations for particular database, if you allow to edits generated annotations for specific classes. In any case I suggest you to check usage of BLOB. PostgreSQL has two ways to handle this byte[] and large object. Hibernate actually supports both, but sometimes this may be little tricky, especially with auto generation. In such case hibernate specific annotations may help. Regards, Radosław Smogura Dnia Åroda, 2 maja 2012 12:15:35 Bata Degen pisze: > Hi list, > > what is your choice of trust when it comes to Java persistence libraries? > > NetBeans gives me these out of the box: > EclipseLink (JPA 2.0) > Hibernate (JPA 1.0) > TopLink Essentials (JPA 1.0) > > Is any of them known to work very well together with PostgreSQL? Or what > else can you recommend? > > I am looking for a solution to do this (the direction is important, it's > not the other way around): > XML-Schema --[via Hyperjaxb3]--> annotated Java classes --[via JPA]--> > PostgreSQL > > I've already managed to do the first two steps but would appreciate your > advice on the last step. I've done loads of tutorials. This one > http://bit.ly/b7vCkF for example employs Hibernate and the cool thing is > that you can let the relations be created for you automatically. But it > uses Apache Derby as the database backend. This is not what I want. I > want to use PostgreSQL. But when exchanging Derby for PostgreSQL > relations won't be created automatically anymore. > > Has anyone done such magic things successfully with PostgreSQL and if > so, which persistence library where you using? > > Thank you guys for your feedback! > > Regards, > Bata