序列没有生成

时间:2016-07-15 08:58:53

标签: java mysql oracle hibernate

我正在尝试使用两种数据库连接形式持久性API

  1. MySql连接
  2. Oracle连接。
  3. 的persistence.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    
        <persistence-unit name="futurepay">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>jdbc/futurepay</jta-data-source>
            <properties>
                <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
                <property name="hibernate.show_sql" value="true" />
                <property name="hibernate.default_schema" value="futurepay" />
            </properties>
        </persistence-unit>
    
        <persistence-unit name="bbpcOracle">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>oracle/bbpc</jta-data-source>
            <properties>
                <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
                <property name="hibernate.show_sql" value="true" />
            </properties>
        </persistence-unit>
    </persistence>
    

    我在jta下面使用了两个entitymange:

    @PersistenceContext(unitName = "futurepay", type=     PersistenceContextType.TRANSACTION)
    public EntityManager futurePayEntityManager;
    
    @PersistenceContext(unitName = "bbpcOracle", type= PersistenceContextType.TRANSACTION)
    public EntityManager bbpcPayEntityManager;
    

    在下面的课程中,我使用的是bbpcEntityManager:

    public class SapfiPostionDAOImpl extends GenericDAOImpl implements ISapfiPostionDAO {
            private static final Logger LOGGER = Logger.getLogger(SapfiPostionDAOImpl.class);   
    
            @SuppressWarnings("unchecked")
            @Override
            public List<ShygSapPostHeader> getCustomerFileReqDtls(int statusId) {
                LOGGER.info("getCustomerFileReqDtls");
                List<ShygSapPostHeader> resultList = new ArrayList<>();
                Query query = bbpcPayEntityManager.createNamedQuery("ShygSapPostHeader.getDetails");
    
                try {
                    resultList = query.getResultList();
                } 
                catch (Exception e) {
                    LOGGER.info("Exception occured while fetching data from ShygSapPostHeader"+e);
                }
    
                return resultList;
            }
        }
    

    我正在使用一些用于mysql的表和一些来自oracle的表。在oracle表中我使用了序列生成器。

    例如:

    @Entity
    @Table(name = "SHYG_SAP_POST_HEADER")
    @NamedQueries({
      @NamedQuery(name = "ShygSapPostHeader.getDetails",query="select model from ShygSapPostHeader")
    })
    @SequenceGenerator(name = "SAP_POSTING_SEQ_GENERATOR", sequenceName = "SAP_POSTING_SEQ", initialValue = 1, allocationSize = 1)
    public class ShygSapPostHeader implements Serializable {
        private static final long serialVersionUID = 1L;
    
        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SAP_POSTING_SEQ_GENERATOR")
        @Column(name = "SAP_POST_ID")
        private Long sapPostId;
        @Column(name = "STORE_CODE")
        private String storeCode;
        @Column(name = "REQUEST_DATE")
        private String requestDate;
    
       .............
       .............
    

    但是当我要在glassfish中部署它时,我会遇到异常。

    例外:

    Severe: Exception while preparing the app : [PersistenceUnit: futurepay] Unable to build EntityManagerFactory
    javax.persistence.PersistenceException: [PersistenceUnit: futurepay] Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:892)
        at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
        at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:206)
        at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:120)
        at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:224)
        at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:495)
        at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:233)
        at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:871)
        at org.glassfish.javaee.full.deployment.EarDeployer.prepareBundle(EarDeployer.java:290)
        at org.glassfish.javaee.full.deployment.EarDeployer.access$200(EarDeployer.java:86)
        at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:141)
        at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:138)
        at org.glassfish.javaee.full.deployment.EarDeployer.doOnBundles(EarDeployer.java:215)
        at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllTypedBundles(EarDeployer.java:224)
        at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllBundles(EarDeployer.java:250)
        at org.glassfish.javaee.full.deployment.EarDeployer.prepare(EarDeployer.java:138)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:871)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:410)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
        at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
        at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
        at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
        at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
        at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
        at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: org.hibernate.MappingException: Could not instantiate id generator [entity-name=com.bbpc.model.ShygSapPostHeader]
        at org.hibernate.id.factory.DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.java:117)
        at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:177)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:257)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:883)
        ... 46 more
    Caused by: org.hibernate.MappingException: Dialect does not support sequences
        at org.hibernate.dialect.Dialect.getSequenceNextValString(Dialect.java:668)
        at org.hibernate.id.SequenceGenerator.configure(SequenceGenerator.java:97)
        at org.hibernate.id.SequenceHiLoGenerator.configure(SequenceHiLoGenerator.java:64)
        at org.hibernate.id.factory.DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.java:110)
        ... 51 more
    

    如果我从类中删除序列生成器部分,那么它的工作正常。但我需要序列生成器。

    那么为什么当我使用序列生成器时会发生这种异常呢?

0 个答案:

没有答案