2 PUs / Hibernate / JPA no JBoss

3 respostas
J

Pessoal, bom dia!

Tenho uma aplicação que olha para duas PUs diferentes. A aplicação roda no glassfish, mas não roda no JBoss.

Meu persistence.xml está assim:

<?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="sagirPU" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:/sagir</jta-data-source>
        <properties>
            <property name="hibernate.archive.autodetection" value="class" />
        </properties>
    </persistence-unit>
    <persistence-unit name="sagir_dw_PU" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:/sagir_dw</jta-data-source>
        <properties>
            <property name="hibernate.archive.autodetection" value="class" />
        </properties>
    </persistence-unit>
</persistence>

A exceção que está dando é:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'Daily_Allocations'.
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454)
	at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:388)
	at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:338)
	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:185)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:160)
	at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:281)
	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:342)
	at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
	at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
	at org.hibernate.loader.Loader.doQuery(Loader.java:697)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
	at org.hibernate.loader.Loader.doList(Loader.java:2228)
	... 78 more
Trecho de uma classe JPA:
@PersistenceUnit(unitName = "sagir_dw_PU")
    private EntityManagerFactory emf = null;

    public EntityManager getEntityManager() {
        return emf.createEntityManager();
    }

    public DailyAllocations findDailyAllocation(Integer id) {
        EntityManager em = getEntityManager();
        try {
            return em.find(DailyAllocations.class, id);
        } finally {
            em.close();
        }
    }
Trecho da entity DailyAllocations:
@Entity
@Table(name = "Daily_Allocations")
@NamedQueries({@NamedQuery(name = "DailyAllocations.findAll", query =
                                                              "SELECT d FROM DailyAllocations d"),
               @NamedQuery(name = "DailyAllocations.findByDailyAllocationsid", query =
                                                                               "SELECT d FROM DailyAllocations d WHERE d.dailyAllocationsid = :dailyAllocationsid"),
               @NamedQuery(name = "DailyAllocations.findByAllocationDate", query =
                                                                           "SELECT d FROM DailyAllocations d WHERE d.allocationDate = :allocationDate"),
               @NamedQuery(name = "DailyAllocations.findByDLQty", query =
                                                                  "SELECT d FROM DailyAllocations d WHERE d.dLQty = :dLQty"),
               @NamedQuery(name = "DailyAllocations.findByDLHours", query =
                                                                    "SELECT d FROM DailyAllocations d WHERE d.dLHours = :dLHours"),
               @NamedQuery(name = "DailyAllocations.findByIDLQty", query =
                                                                   "SELECT d FROM DailyAllocations d WHERE d.iDLQty = :iDLQty"),
               @NamedQuery(name = "DailyAllocations.findByIDLHours", query =
                                                                     "SELECT d FROM DailyAllocations d WHERE d.iDLHours = :iDLHours"),
               @NamedQuery(name = "DailyAllocations.findByDLFixoQty", query =
                                                                      "SELECT d FROM DailyAllocations d WHERE d.dLFixoQty = :dLFixoQty"),
               @NamedQuery(name = "DailyAllocations.findByDLFixoHours", query =
                                                                        "SELECT d FROM DailyAllocations d WHERE d.dLFixoHours = :dLFixoHours"),
               @NamedQuery(name = "DailyAllocations.findByBckQty", query =
                                                                   "SELECT d FROM DailyAllocations d WHERE d.bckQty = :bckQty"),
               @NamedQuery(name = "DailyAllocations.findByBckHours", query =
                                                                     "SELECT d FROM DailyAllocations d WHERE d.bckHours = :bckHours")})
public class DailyAllocations implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "Daily_Allocations_id")
    private Integer dailyAllocationsid;
    @Basic(optional = false)
    @Column(name = "Allocation_Date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date allocationDate;

Alguém consegue me ajudar?
Obrigado,
Jefferson

3 Respostas

R

Parece que ele não está encontrando a tabela “Daily_Allocations” no seu database.

J

Oi,
sim, parece. Mas ela está lá.
A aplicação funciona no glassfish.

Obrigado pela resposta.
Jefferson

J

Resolvi o problema trocando de 'application-managed' para 'container-managed':

@PersistenceContext(name="persistence/B1", unitName="B1PU")
public class T1JpaController {

    ...
    public EntityManager getEntityManager() {
        EntityManager em = null;
        Context initCtx;
        try {
            initCtx = new InitialContext();
            em =
            (EntityManager) initCtx.lookup("java:comp/env/persistence/B1");
        } catch (NamingException ex) {
            Logger.getLogger(T1JpaController.class.getName()).log(Level.SEVERE, null, ex);
        }
        return em;
    }
Criado 5 de novembro de 2009
Ultima resposta 6 de nov. de 2009
Respostas 3
Participantes 2