Java 在使用MS SQL 2008的Hibernate 4期间,如何修复setResultTransformer方法中的异常?
如何在休眠期间修复setResultTransformer方法中的异常 我有一个调用命名查询的方法Java 在使用MS SQL 2008的Hibernate 4期间,如何修复setResultTransformer方法中的异常?,java,hibernate,stored-procedures,nullpointerexception,named-query,Java,Hibernate,Stored Procedures,Nullpointerexception,Named Query,如何在休眠期间修复setResultTransformer方法中的异常 我有一个调用命名查询的方法 SessionFactory sf = HibernateUtil.createSessionFactory(); Session session = sf.openSession(); Transaction t = session.beginTransaction(); Query qr = session.getNamedQuery("Pr
SessionFactory sf = HibernateUtil.createSessionFactory();
Session session = sf.openSession();
Transaction t = session.beginTransaction();
Query qr = session.getNamedQuery("Product_Create");
qr.setParameter("@Return", 0);
qr.setParameter("@ProdIDID", 0);
qr.setParameter("@PassID", new BigInteger("9999999999"));
qr.setParameter("@Amount", new BigInteger("7777777777"));
t.commit();
List<CreatedCardBean> list = qr.setResultTransformer(Transformers.aliasToBean(CreatedCardBean.class)).list();
for(int i=0; i<list.size(); i++){
CreatedCardBean card = (CreatedCardBean)list.get(i);
LOG.info(String.valueOf(card.getCardId()));
}
我的hibernate配置如下所示:
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="connection.url">jdbc:sqlserver://....</property>
<property name="connection.username">user</property>
<property name="connection.password">pass</property>
<property name="connection.pool_size">10</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property>
<property name="hibernate.connection.autocommit">true</property>
<!--<property name="current_session_context_class">thread</property> -->
<mapping resource="com/comp/common/Product_Create.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>
有人能帮我解决这个异常吗
更新
CreatedCardBean是:
public class CreatedCardBean {
private int ReturnValue;
private long prodID;
public int getReturnValue() {
return ReturnValue;
}
public void setReturnValue(int returnValue) {
ReturnValue = returnValue;
}
public long getProdID() {
return prodID;
}
public void setProdID(long prodID) {
this.prodID = prodID;
}
}
可能是
存储过程引发了一些异常
在执行查询后尝试关闭事务。transacrion classt中没有close方法。我添加了session.close(),但问题仍然存在。存储过程毫无例外地工作。我的代码似乎无法捕获输出参数并将其放入CreatedCardBean。仍然需要帮助。可能是存储过程引发了一些异常
请在执行查询后尝试关闭事务。transacrion classt中没有close方法。我添加了session.close(),但问题仍然存在。存储过程毫无例外地工作。我的代码似乎无法捕获输出参数并将其放入CreatedCardBean。仍然需要帮助。
<hibernate-mapping>
<sql-query name="Product_Create" callable="true">
<return-scalar column = "retVal" type="int"/>
<return-scalar column = "cardId" type="long"/>
<![CDATA[{CALL Product_Create (:@Return, :@ProdID, :@PassID, :@Amount)}]]>
</sql-query>
</hibernate-mapping>
INFO : [окт-06 11:49:56,775] annotations.common.Version - HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
INFO : [окт-06 11:49:56,788] org.hibernate.Version - HHH000412: Hibernate Core {4.3.8.Final}
INFO : [окт-06 11:49:56,791] hibernate.cfg.Environment - HHH000206: hibernate.properties not found
INFO : [окт-06 11:49:56,794] hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
INFO : [окт-06 11:49:56,828] hibernate.cfg.Configuration - HHH000043: Configuring from resource: /hibernate.cfg.xml
INFO : [окт-06 11:49:56,828] hibernate.cfg.Configuration - HHH000040: Configuration resource: /hibernate.cfg.xml
WARN : [окт-06 11:49:56,861] util.xml.DTDEntityResolver - HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
INFO : [окт-06 11:49:56,888] hibernate.cfg.Configuration - HHH000221: Reading mappings from resource: com/comp/common/Product_Create.hbm.xml
WARN : [окт-06 11:49:56,919] util.xml.DTDEntityResolver - HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
...
...
INFO : [окт-06 11:49:56,953] hibernate.cfg.Configuration - HHH000041: Configured SessionFactory: null
WARN : [окт-06 11:49:57,091] connections.internal.DriverManagerConnectionProviderImpl - HHH000402: Using Hibernate built-in connection pool (not for production use!)
INFO : [окт-06 11:49:57,202] connections.internal.DriverManagerConnectionProviderImpl - HHH000006: Autocommit mode: true
INFO : [окт-06 11:49:57,204] connections.internal.DriverManagerConnectionProviderImpl - HHH000115: Hibernate connection pool size: 10 (min=1)
INFO : [окт-06 11:49:57,895] hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.SQLServerDialect
INFO : [окт-06 11:49:57,986] transaction.internal.TransactionFactoryInitiator - HHH000399: Using default transaction strategy (direct JDBC transactions)
INFO : [окт-06 11:49:57,992] internal.ast.ASTQueryTranslatorFactory - HHH000397: Using ASTQueryTranslatorFactory
INFO : [окт-06 11:49:58,056] internal.util.Version - HV000001: Hibernate Validator 5.1.3.Final
Hibernate: {CALL Product_Create (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}
WARN : [окт-06 11:50:02,280] jdbc.spi.SqlExceptionHelper - SQL Warning Code: 0, SQLState: S0001
....
WARN : [окт-06 11:50:02,301] jdbc.spi.SqlExceptionHelper - ProductID = 78712878
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.loader.Loader.processResultSet(Loader.java:950)
at org.hibernate.loader.Loader.doQuery(Loader.java:921)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
at org.hibernate.loader.Loader.doList(Loader.java:2554)
at org.hibernate.loader.Loader.doList(Loader.java:2540)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
at org.hibernate.loader.Loader.list(Loader.java:2365)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:353)
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1873)
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:311)
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:141)
public class CreatedCardBean {
private int ReturnValue;
private long prodID;
public int getReturnValue() {
return ReturnValue;
}
public void setReturnValue(int returnValue) {
ReturnValue = returnValue;
}
public long getProdID() {
return prodID;
}
public void setProdID(long prodID) {
this.prodID = prodID;
}
}