hibernate一直报错

whkokotime殇 2014-08-30 07:06:44
八月 30, 2014 6:53:38 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
八月 30, 2014 6:53:38 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.6.Final}
八月 30, 2014 6:53:38 下午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
八月 30, 2014 6:53:38 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
八月 30, 2014 6:53:38 下午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
八月 30, 2014 6:53:38 下午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml

版本4.3.6
...全文
388 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
clover灬 2014-09-02
  • 打赏
  • 举报
回复
引用 10 楼 whkokotimeZuo 的回复:
这种写法: sessionFactory = configuration.buildSessionFactory(serviceRegistry); 总是错 换了过时的写法 sessionFactory = configuration.buildSessionFactory(); 就好了 目前还不知道原因
我用的就是第一种方式,也没有报错啊。是不是model类里面少了get方法,报错信息有提示说的
新铺村长 2014-09-02
  • 打赏
  • 举报
回复
应该是vo类中缺少相应的get方法,仔细检查下!
哒哒哒打代码 2014-09-01
  • 打赏
  • 举报
回复
org.hibernate.PropertyNotFoundException: Could not find a getter for id in class com.HibernateTest Test类中的id 属性没有GET方法
whkokotime殇 2014-09-01
  • 打赏
  • 举报
回复
这种写法: sessionFactory = configuration.buildSessionFactory(serviceRegistry); 总是错 换了过时的写法 sessionFactory = configuration.buildSessionFactory(); 就好了 目前还不知道原因
yanghongjy 2014-08-31
  • 打赏
  • 举报
回复
<class name="com.HibernateTest" table="top"> <id name="id" column="id" type="java.lang.Integer"> <generator class="native"/> </id> 这个 id 是不是没有 get set 方法
whkokotime殇 2014-08-30
  • 打赏
  • 举报
回复
sessionFactory = configuration.buildSessionFactory(serviceRegistry); Junit一直报这一行错误 22行
whkokotime殇 2014-08-30
  • 打赏
  • 举报
回复
hibernate调用

package com;

import static org.junit.Assert.*;

import java.sql.Date;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.junit.Test;

public class HibernateTest {

	@Test
	public void test() {
		Configuration configuration = new Configuration().configure();
		SessionFactory sessionFactory = null;
		ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
		sessionFactory = configuration.buildSessionFactory(serviceRegistry);

		
		
		
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		News news = new News("jklajdf@qq.com","asdasds",new Date(new java.util.Date().getTime()));
		session.save(news);
		transaction.commit();
		session.close();
		sessionFactory.close();
	}
}

whkokotime殇 2014-08-30
  • 打赏
  • 举报
回复
数据库没有东西
只愿云淡风清 2014-08-30
  • 打赏
  • 举报
回复
只有配置信息,你是去数据的时候报的错吧,看一下数据库里有没有东西
whkokotime殇 2014-08-30
  • 打赏
  • 举报
回复
Console

八月 30, 2014 10:28:28 下午 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
八月 30, 2014 10:28:28 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.4.Final}
八月 30, 2014 10:28:28 下午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
八月 30, 2014 10:28:28 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
八月 30, 2014 10:28:28 下午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
八月 30, 2014 10:28:28 下午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
八月 30, 2014 10:28:29 下午 org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: com/News.hbm.xml
八月 30, 2014 10:28:29 下午 org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
八月 30, 2014 10:28:29 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
八月 30, 2014 10:28:29 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 1
八月 30, 2014 10:28:29 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
八月 30, 2014 10:28:29 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/top]
八月 30, 2014 10:28:29 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, password=****}
八月 30, 2014 10:28:29 下午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
八月 30, 2014 10:28:29 下午 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
八月 30, 2014 10:28:29 下午 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
JUnit

org.hibernate.PropertyNotFoundException: Could not find a getter for id in class com.HibernateTest
	at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:316)
	at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:310)
	at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:390)
	at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:75)
	at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:145)
	at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:507)
	at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:146)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
	at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:385)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1790)
	at com.HibernateTest.test(HibernateTest.java:22)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
whkokotime殇 2014-08-30
  • 打赏
  • 举报
回复
hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
         <session-factory>
         
          <!-- 数据库驱动名称 -->
         <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
         <!-- 数据库链接地址 -->
         <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/top</property>
         <!-- 数据库用户名称 -->
         <property name="hibernate.connection.username">root</property>
         <!-- 数据库密码 -->
         <property name="connection.password">topvia</property>
         <!-- 设置数据库连接池默认个数 -->
         <property name="connection.pool_size">1</property>
         <!-- 设置数据库SQL语言类型 -->
         <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
         <!-- 设置是否显示SQL语句-->
         <property name="show_sql">true</property>
         <!-- 设置是否格式化SQL语句 -->
         <property name="format_sql">true</property>
         <!-- 设置使用线程-->
         <property name="current_session_context_class">thread</property>
         <!-- 设置hibernate的映射文件-->
         <mapping  resource="com/News.hbm.xml"/>
         
     </session-factory>
 </hibernate-configuration>
News.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.HibernateTest" table="top">
        <id name="id" column="id" type="java.lang.Integer">
            <generator class="native"/>
        </id>
        <property name="user" type="java.lang.String">
            <column name="user"/>
        </property>
        <property name="pw" type="java.lang.String">
            <column name="pw" />
        </property>
        <property name="time" type="java.sql.Date">
        	<column name="time" />
        </property>
    </class>
</hibernate-mapping>
Thomas.Sir 2014-08-30
  • 打赏
  • 举报
回复
hibernate.properties not found : 估计实体类少Annotation。。。为了更准确,请贴出源代码。

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧