2013-06-27 73 views
0

我是hibernate的新手。使用版本4.2.2與MySQL 4.我得到相同的錯誤。我不知道發生了什麼幫助我。hibernate 4.2.2和mysql。獲取異常java.lang.UnsupportedOperationException:應用程序必須支持

hibernate.cfg.xml文件

<hibernate-configuration> 
<session-factory> 

     <property name="hibernate.connction.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="hibernate.connction.url">jdbc:mysql://localhost:3306/HibernateDB</property> 
     <property name="hibernate.connction.user_name">mysql</property> 
     <property name="hibernate.connction.password">mysql</property> 


     <property name="dialect">org.hibernate.dialect.MySQLDialect</property> 

     <property name="cache.provider_class">org.hibernate.cache.NocacheProvider</property> 

     <property name="show_sql">true</property> 

     <property name="hibernate.hbm2ddl">create</property> 
     <property name="hbm2ddl">craete</property> 

     <mapping class="org.shammu.UserDetails" /> 

</session-factory> 
</hibernate-configuration> 

的UserDetails類

package org.shammu; 
import javax.persistence.Entity; 
import javax.persistence.Id; 

@Entity 
public class UserDetails { 

@Id 
private int userId; 
private String userName; 
public int getUserId() { 
    return userId; 
} 
public void setUserId(int userId) { 
    this.userId = userId; 
} 
public String getUserName() { 
    return userName; 
} 
public void setUserName(String userName) { 
    this.userName = userName; 
} 
} 

我的測試類是:

package org.shammu; 

import org.hibernate.Session; 
import org.hibernate.SessionFactory; 
import org.hibernate.cfg.Configuration; 

public class TestClass { 

/** 
* @param args 
*/ 
public static void main(String[] args) { 
    UserDetails user = new UserDetails(); 
    user.setUserId(1); 
    user.setUserName("Shammu"); 
    @SuppressWarnings("deprecation") 
    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); 
    Session session = sessionFactory.openSession(); 
    session.beginTransaction(); 

    session.save(user); 
    session.getTransaction().commit(); 

} 

} 

控制檯錯誤messag e是:

Jun 28, 2013 1:02:27 AM org.hibernate.annotations.common.Version <clinit> 
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final} 
Jun 28, 2013 1:02:27 AM org.hibernate.Version logVersion 
INFO: HHH000412: Hibernate Core {4.2.2.Final} 
Jun 28, 2013 1:02:27 AM org.hibernate.cfg.Environment <clinit> 
INFO: HHH000206: hibernate.properties not found 
Jun 28, 2013 1:02:27 AM org.hibernate.cfg.Environment buildBytecodeProvider 
INFO: HHH000021: Bytecode provider name : javassist 
Jun 28, 2013 1:02:27 AM org.hibernate.cfg.Configuration configure 
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml 
Jun 28, 2013 1:02:27 AM org.hibernate.cfg.Configuration getConfigurationInputStream 
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml 
Jun 28, 2013 1:02:27 AM org.hibernate.cfg.Configuration doConfigure 
INFO: HHH000041: Configured SessionFactory: null 
Jun 28, 2013 1:02:27 AM org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator initiateService 
WARN: HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections 
Jun 28, 2013 1:02:27 AM org.hibernate.dialect.Dialect <init> 
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect 
Jun 28, 2013 1:02:27 AM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation 
INFO: HHH000422: Disabling contextual LOB creation as connection was null 
Jun 28, 2013 1:02:27 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService 
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions) 
Jun 28, 2013 1:02:27 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init> 
INFO: HHH000397: Using ASTQueryTranslatorFactory 
Exception in thread "main" java.lang.UnsupportedOperationException: The application must supply JDBC connections 
at org.hibernate.service.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection(UserSuppliedConnectionProviderImpl.java:62) 
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:292) 
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214) 
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:157) 
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67) 
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160) 
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1426) 
at org.shammu.TestClass.main(TestClass.java:19) 

我都已經包含在類路徑中使用mysql-connector罐子 請人幫助我..

+0

能否請您粘貼完整的堆棧跟蹤? – zerocool

+0

編輯並添加堆棧跟蹤請檢查 – Shameer

+0

您在您的四個'hibernate.connction ...'屬性中拼錯了'connection'。如果您修復拼寫有什麼幫助? –

回答

1

您的配置文件需要改變一點點:

<property name="hibernate.connection.username">mysql</property> 
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 

hibernate看起來不能連接到數據庫。還要確保您提供的連接URL與數據庫憑證一致。

參照這裏設置屬性名稱的權利:

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/session-configuration.html

+0

它的錯字你的建議有助於TNN .. – Shameer

相關問題