Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Re: manually generating tables after switching postgresql "schema"

I've been able to solve this using EclipseLinks SessionEvents.
This blog post was very helpful:
http://onpersistence.blogspot.com/2010/03/running-sql-script-on-startup-in.html



On Tue, Jun 8, 2010 at 11:49 PM, Dominik Dorn <dominik.dorn@xxxxxxxxx> wrote:
> Hello,
>
> for an university assignment we _have to_ place multiple instances
> of a schema into the same postgresql database.
>
> I'm using EclipseLink 2.0.2 and I'm trying to do it like this, but I'm stuck
>
>        EntityManagerFactoryImpl factory = (EntityManagerFactoryImpl)
> Persistence.createEntityManagerFactory("RestPersistenceUnit");
>
>        EntityManager em = factory.createEntityManager(); // this
> triggers table creation the first time, but fails as there is no
> schema selected
>
>        em.getTransaction().begin();
>        em.createNativeQuery("CREATE SCHEMA test123;").executeUpdate();
>        em.createNativeQuery("SET SEARCH_PATH TO test123;").executeUpdate();
>        em.getTransaction().commit();
>
> // i hoped the following code would now again trigger table creation,
> but it doesn't
>        factory.close();
>        System.out.println("\n\n\n\n\n\nnew");
>
>        factory = (EntityManagerFactoryImpl)
> Persistence.createEntityManagerFactory("RestPersistenceUnit");
>        em = factory.createEntityManager();
>
>
>        SchemaManager schemaManager = new
> SchemaManager(factory.getServerSession());
>
>        schemaManager.outputDDLToDatabase(); // this doesnt work either
>
>
> the persistence.xml looks like this:
>    <persistence-unit name="RestPersistenceUnit">
>        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
>        <class>com.dominikdorn.tuwien.evs.rest.domain.Rack</class>
>        <class>com.dominikdorn.tuwien.evs.rest.domain.Item</class>
>        <class>com.dominikdorn.tuwien.evs.rest.domain.Placement</class>
>        <properties>
>            <property name="javax.persistence.transactionType"
> value="RESOURCE_LOCAL" />
>            <property name="javax.persistence.jdbc.driver"
> value="org.postgresql.Driver" />
>            <property name="javax.persistence.jdbc.url"
> value="jdbc:postgresql://127.0.0.1:5432/evs"/>
>            <property name="javax.persistence.jdbc.user" value="evs"/>
>            <property name="javax.persistence.jdbc.password" value="evs10"/>
>            <property name="eclipselink.target-database" value="POSTGRESQL" />
>            <!--<property name="eclipselink.ddl-generation"
> value="create-tables" />-->
>            <property name="eclipselink.ddl-generation"
> value="drop-and-create-tables" />
>            <property name="eclipselink.create-ddl-jdbc-file-name"
> value="create.sql"/>
>            <property name="eclipselink.drop-ddl-jdbc-file-name"
> value="drop.sql"/>
>            <property name="eclipselink.ddl-generation.output-mode"
> value="both"/>
>        </properties>
>    </persistence-unit>
>
> So basically what I need to do is:
> 1. create a new "schema" with a specific name
> 2. set the search_path to this schema
> 3. let eclipselink create the tables on the connection where the
> search_path was altered.
> 4. use the specified search_path for every EntityManager created from
> the Factory
>
> the problem I'm facing:
>
> EclipseLink tries to create the tables when I call
> emf.createEntityManager(); which
> fails because there is no schema selected.
>
> The code above may be completely wrong.. its just my naive try to get it working
> after a lot of googling and finally sniffing around in the sourcecode
> and attaching
> a debugger.
>
>
> Any help greatly appreciated!
>
>
> Thanks a lot!
>
> Kind regards,
> Dominik
> --
> Dominik Dorn
> http://dominikdorn.com
>



-- 
Dominik Dorn
http://dominikdorn.com

http://www.lyrix.eu/lyrics/Sido/


Back to the top