Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用Hibernate连接到Informix_Java_Hibernate_Informix_Hibernate 5.x - Fatal编程技术网

Java 无法使用Hibernate连接到Informix

Java 无法使用Hibernate连接到Informix,java,hibernate,informix,hibernate-5.x,Java,Hibernate,Informix,Hibernate 5.x,我试图使用Hibernate 5.2.10连接到Informix数据库,但是程序没有响应,并且在没有抛出任何错误消息的情况下被卡住 我在控制台上找不到任何东西。有没有关于我犯了什么错误的建议?我刚开始冬眠 hibernate.cfg.xml <property name="connection.driver_class">com.informix.jdbc.IfxDriver</property> <property name="connection.url">

我试图使用Hibernate 5.2.10连接到Informix数据库,但是程序没有响应,并且在没有抛出任何错误消息的情况下被卡住

我在控制台上找不到任何东西。有没有关于我犯了什么错误的建议?我刚开始冬眠

hibernate.cfg.xml

<property name="connection.driver_class">com.informix.jdbc.IfxDriver</property>
<property name="connection.url">jdbc:informixsqli://****:1528/****:informixserver=*****</property>
<property name="connection.username">*****</property>
<property name="connection.password">*****</property>
信息混合测试

 public static CustomerInvoice lookupInvoice(String invoiceNumber){
    Session session = null;
    List<CustomerInvoice> customerInvoiceList = new ArrayList<CustomerInvoice>();
    CustomerInvoice customerInvoice = null;
    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query query = session.createQuery(invoiceByNumber);
        query.setParameter("invoiceNumber", invoiceNumber+"%");
        customerInvoiceList = ((org.hibernate.query.Query) query).list();

    } catch (Exception e) {
        e.printStackTrace();
        session.close();
    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }


    if(customerInvoiceList.size()>0){
        customerInvoice = customerInvoiceList.get(0);
    }

    return customerInvoice;

}
公共静态CustomerVoice lookupInvoice(字符串invoiceNumber){
会话=空;
List customerInvoiceList=新建ArrayList();
CustomerInvoice CustomerInvoice=null;
试一试{
session=HibernateUtil.getSessionFactory().openSession();
Query=session.createQuery(invoiceynumber);
query.setParameter(“invoiceNumber”,invoiceNumber+“%”);
customerInvoiceList=((org.hibernate.query.query)query).list();
}捕获(例外e){
e、 printStackTrace();
session.close();
}最后{
if(session!=null&&session.isOpen()){
session.close();
}
}
如果(customerInvoiceList.size()>0){
customerInvoice=customerInvoiceList.get(0);
}
返回客户语音;
}

我用5.2和最新的jdbc驱动程序做了一个快速测试,它似乎对我很好。我正在使用HibernateUtil和类似的Hibernate配置文件:

D:\Infx\work\Hibernate>java list
Sep 18, 2017 10:53:49 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.11.Final}
Sep 18, 2017 10:53:49 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Sep 18, 2017 10:53:49 AM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
Sep 18, 2017 10:53:50 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Sep 18, 2017 10:53:50 AM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.informix.jdbc.IfxDriver] at URL [jdbc:informix-sqli://420ito:9088/stores7:INFORMIXSERVER=ids1210;user=informix;password=dummy;]
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {}
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Sep 18, 2017 10:53:52 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.InformixDialect
Sep 18, 2017 10:53:53 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@37ebc9d8] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Sep 18, 2017 10:53:55 AM org.hibernate.hql.internal.QueryTranslatorFactoryInitiator initiateService
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select state0_.id as id1_0_, state0_.code as code2_0_, state0_.sname as sname3_0_, state0_.next_state_id as next_sta4_0_ from States state0_ order by state0_.id asc
test, test
test, test
Sep 18, 2017 10:53:55 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:informix-sqli://420ito:9088/stores7:INFORMIXSERVER=ids1210;user=informix;password=dummy;]

D:\Infx\work\Hibernate>

但我想这和你已经拥有的应该没什么不同

谢谢你帮我的忙。在我从hibernate配置文件中删除此属性后,问题得到了解决

<property name="hbm2ddl.auto">update</property> 
更新

Ifx连接(在openSession()中)后可能会出现异常,但未在控制台中记录/转储该异常。在尝试连接到虚拟数据库或使用错误的密码时,是否会出现异常?我在其他任何地方都看不到异常,我使用的是Informix JDBC驱动程序的4.10.9版本。您使用了哪个版本来实现此功能?JC8和JC9之间的版本;)刚用JC9测试过,效果也一样。使用虚拟用户时是否看到异常?
D:\Infx\work\Hibernate>java list
Sep 18, 2017 10:53:49 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.11.Final}
Sep 18, 2017 10:53:49 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Sep 18, 2017 10:53:49 AM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
Sep 18, 2017 10:53:50 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Sep 18, 2017 10:53:50 AM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.informix.jdbc.IfxDriver] at URL [jdbc:informix-sqli://420ito:9088/stores7:INFORMIXSERVER=ids1210;user=informix;password=dummy;]
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {}
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Sep 18, 2017 10:53:51 AM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Sep 18, 2017 10:53:52 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.InformixDialect
Sep 18, 2017 10:53:53 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@37ebc9d8] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Sep 18, 2017 10:53:55 AM org.hibernate.hql.internal.QueryTranslatorFactoryInitiator initiateService
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select state0_.id as id1_0_, state0_.code as code2_0_, state0_.sname as sname3_0_, state0_.next_state_id as next_sta4_0_ from States state0_ order by state0_.id asc
test, test
test, test
Sep 18, 2017 10:53:55 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:informix-sqli://420ito:9088/stores7:INFORMIXSERVER=ids1210;user=informix;password=dummy;]

D:\Infx\work\Hibernate>
D:\Infx\work\Hibernate>java list
Sep 18, 2017 10:54:42 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.11.Final}
Sep 18, 2017 10:54:42 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Sep 18, 2017 10:54:42 AM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
Sep 18, 2017 10:54:42 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Sep 18, 2017 10:54:42 AM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
Sep 18, 2017 10:54:44 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Sep 18, 2017 10:54:44 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.informix.jdbc.IfxDriver] at URL [jdbc:informix-sqli://420ito:9088/stores7:INFORMIXSERVER=ids1210;user=informix;password=dummy;]
Sep 18, 2017 10:54:44 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {}
Sep 18, 2017 10:54:44 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Sep 18, 2017 10:54:44 AM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Sep 18, 2017 10:54:44 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.InformixDialect
Sep 18, 2017 10:54:46 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@37ebc9d8] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
        at list.main(list.java:12)
....
.... 
....
D:\Infx\work\Hibernate>cat set5.cmd
@echo off
set CLASSPATH=
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\javassist-3.20.0-GA.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\dom4j-1.6.1.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\hibernate-jpa-2.1-api-1.0.0.Final.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\hibernate-core-5.2.11.Final.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\hibernate-commons-annotations-5.0.1.Final.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\ifxjdbc.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\jta-1.1.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\classmate-1.3.0.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\jboss-logging-3.3.0.Final.jar
set CLASSPATH=%CLASSPATH%;D:\infx\work\Hibernate\lib5\antlr-2.7.7.jar
set CLASSPATH=%CLASSPATH%;.

D:\Infx\work\Hibernate>cat hibernate.cfg.xml
<?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="connection.driver_class">com.informix.jdbc.IfxDriver
   </property>
   <property
       name="connection.url">jdbc:informix-sqli://420ito:9088/stores7:INFORMIXSERVER=ids1210;user=informix;password=dummy;
   </property>
   <property
      name="dialect">org.hibernate.dialect.InformixDialect
   </property>
    <property name="hibernate.show_sql">true
   </property>

   <property
       name="current_session_context_class">thread
   </property>
<property name="hbm2ddl.auto">update</property>

   <mapping resource="State.hbm.xml"/>
   </session-factory>

</hibernate-configuration>

D:\Infx\work\Hibernate>cat State.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
   <class
      name="State"
      table="States">
      <id
         name="id"
         column="id">
         <generator class="increment"/>
      </id>

      <property
         name="code"
         column="code"/>
      <property
         name="sname"
         column="sname"/>
      <many-to-one
         name="nextState"
         cascade="all"
         column="next_state_id"/>
   </class>
</hibernate-mapping>

D:\Infx\work\Hibernate>cat HibernateUtil.java
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

public class HibernateUtil { private static final SessionFactory sessionFactory = buildSessionFactory();

public static SessionFactory getSessionFactory() {
    return sessionFactory;
}

private static SessionFactory buildSessionFactory(){
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
    try {
        return new
     MetadataSources(registry).buildMetadata().buildSessionFactory();
    }
    catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        StandardServiceRegistryBuilder.destroy( registry );
        throw new ExceptionInInitializerError(ex);
    }
}

  public static void shutdown() {
// Close caches and connection pools
     getSessionFactory().close();
  }

}

D:\Infx\work\Hibernate>cat create.java
import java.util.*;
import org.hibernate.*;
import javax.persistence.*;

public class create {
 public static void main(String[] args) {

   java.util.logging.Logger.getLogger("org.hibernate").setLevel(java.util.logging.Level.FINEST  );
   java.util.logging.Logger.getLogger("org.hibernate").setLevel(java.util.logging.Level.SEVERE  );
   Session Session = HibernateUtil.getSessionFactory().openSession();
   Transaction Transaction = Session.beginTransaction();

   State myState = new State();
   myState.setcode(args[0]);
   myState.setsname(args[1]);
   Long stateId = (Long) Session.save(myState);

   System.out.println("Stated added: "+myState.getcode()+", "+myState.getsname() );

   Transaction.commit();
   Session.close();
// Shutting down the application
   HibernateUtil.shutdown();
  }
}

D:\Infx\work\Hibernate>cat list.java
import java.util.*;
import org.hibernate.*;
import javax.persistence.*;

public class list {
 public static void main(String[] args) {

   java.util.logging.Logger.getLogger("org.hibernate").setLevel(java.util.logging.Level.FINEST  ); 
   java.util.logging.Logger.getLogger("org.hibernate").setLevel(java.util.logging.Level.SEVERE  );

   Session newSession = HibernateUtil.getSessionFactory().openSession();
   Transaction newTransaction = newSession.beginTransaction();
   List states = newSession.createQuery("from State order by id asc").list();

   for ( Iterator iter = states.iterator();
      iter.hasNext(); ) {
      State state = (State) iter.next();
      System.out.println(state.getcode() +", " + state.getsname() );
   }
   newTransaction.commit();
   newSession.close();

   HibernateUtil.shutdown();
  }
}
D:\Infx\work\Hibernate>
D:\Infx\work\Hibernate>java com.informix.jdbc.Version
IBM Informix JDBC Driver Version 4.10.JC9

D:\Infx\work\Hibernate>javac create.java

D:\Infx\work\Hibernate>javac list.java

D:\Infx\work\Hibernate>java create test1 test2
Hibernate: select max(id) from States
Stated added: test1, test2
Hibernate: insert into States (code, sname, next_state_id, id) values (?, ?, ?, ?)

D:\Infx\work\Hibernate>java list
Hibernate: select state0_.id as id1_0_, state0_.code as code2_0_, state0_.sname as sname3_0_, state0_.next_state_id as next_sta4_0_ from States state0_ order by state0_.id asc
test, test
test, test
test1, test2

D:\Infx\work\Hibernate>
<property name="hbm2ddl.auto">update</property>