[Resolvido] Problema com schema/postgres

1 resposta
Hebert_Coelho

Oi pessoal, blz?

Estou tendo um pequeno problema com a criação automática de schemas.

Preciso gerar o schema de modo automático, mas não consegui achar onde fica essa opção.

Consigo gerar a tabela no schema q eu quero, mas a sequence acaba indo para a public.

Preciso colocar o schema em um xml pois essa app irá rodar em mais de uma aplicação.

Vou colocar abaixo, o meu código.

Mesmo com a opção hibernate.default_schema, o schema padrão não está funcionando como teoricamente deveria.

hibernate.cfg:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
    <property name="hibernate.connection.url">jdbc:postgresql://127.0.0.1:5432/postgres</property>
    <property name="hibernate.connection.username">postgres</property>
    <property name="hibernate.connection.password">hello</property>
    <property name="hibernate.default_schema">ola</property>
  </session-factory>
</hibernate-configuration>
sun-resources.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
<resources>
    <jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.postgresql.ds.PGSimpleDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="post-gre-sql_postgres_postgresPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
        <property name="serverName" value="127.0.0.1"/>
        <property name="portNumber" value="5432"/>
        <property name="databaseName" value="postgres"/>
        <property name="User" value="postgres"/>
        <property name="Password" value="pois13eh!"/>
        <property name="URL" value="jdbc:postgresql://127.0.0.1:5432/postgres/"/>
        <property name="driverClass" value="org.postgresql.Driver"/>
    </jdbc-connection-pool>
    <jdbc-resource enabled="true" jndi-name="postgres" object-type="user" pool-name="post-gre-sql_postgres_postgresPool"/>
</resources>
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="TestandoEJBPU" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>postgres</jta-data-source>
    <properties>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
  </persistence-unit>
</persistence>

Obrigado pela ajuda.

1 Resposta

Hebert_Coelho

Problema resolvido! :mrgreen:

Deixei a opção hibernate.default_schema no persistence.xml. E limpei o cache! 8)

Criado 7 de fevereiro de 2011
Ultima resposta 7 de fev. de 2011
Respostas 1
Participantes 1