ysheng随便学学 2016-11-29 11:45 采纳率: 0%
浏览 2284

hibernate5 问题,使用注解

 <?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.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/mytest</property>
        <property name="connection.username">root</property>
        <property name="connection.password">zys123</property>
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hbm2ddl.auto">update</property>
        <mapping class="persistence.Message" />
    </session-factory>
 </hibernate-configuration>

 package persistence;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;


@Entity
public class Message {
    @Id
    @GeneratedValue(generator="ID_GENERATOR")
    private Long id;

    private String text;
    private Message nextMessage;
    Message(){}
    public Message(String text){
        this.text = text;
    }
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getText() {
        return text;
    }
    public void setText(String text) {
        this.text = text;
    }
    public Message getNextMessage() {
        return nextMessage;
    }
    public void setNextMessage(Message nextMessage) {
        this.nextMessage = nextMessage;
    }
}

package Deal;

import java.util.*;
import org.hibernate.*;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;


import persistence.*;

public class Hello {
    public static void main(String[] args){
        StandardServiceRegistry  serviceRegistry=new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build(); 
        MetadataSources m = new MetadataSources(serviceRegistry);
        m.addAnnotatedClass(persistence.Message.class);
        SessionFactory sessionFactory=m.buildMetadata(serviceRegistry).buildSessionFactory();

        Session session = sessionFactory.openSession();
        Transaction tx = session.beginTransaction();
        Message message = new Message("Hello World");
        session.save(message);
    //  session.persist(message);

        tx.commit();
        session.close();

        Session newSession = sessionFactory.openSession();
        Transaction newTransaction = newSession.beginTransaction();
        List messages = newSession.createQuery("from Message m order by m.text asc").getResultList();
        System.out.println(messages.size()+"message(s) found:");
        for(Iterator<Message> iter = messages.iterator();iter.hasNext();){
            Message loadeMsg = iter.next();
            System.out.println(loadeMsg.getText());
        }
        newTransaction.commit();
        newSession.close();
        sessionFactory.close();
    }
}

十一月 29, 2016 7:42:38 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.3.Final}
十一月 29, 2016 7:42:38 下午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
十一月 29, 2016 7:42:38 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
十一月 29, 2016 7:42:38 下午 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.
十一月 29, 2016 7:42:38 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
十一月 29, 2016 7:42:38 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
十一月 29, 2016 7:42:38 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/mytest]
十一月 29, 2016 7:42:38 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
十一月 29, 2016 7:42:38 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
十一月 29, 2016 7:42:38 下午 org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Tue Nov 29 19:42:38 CST 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
十一月 29, 2016 7:42:38 下午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/classmate/TypeResolver
    at org.hibernate.boot.internal.ClassmateContext.<init>(ClassmateContext.java:16)
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:118)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:113)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
    at org.hibernate.boot.MetadataSources.buildMetadata(MetadataSources.java:183)
    at Deal.Hello.main(Hello.java:17)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.classmate.TypeResolver
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 8 more

求大神帮忙,调试好长时间不行啊

  • 写回答

3条回答 默认 最新

  • devmiao 2016-11-29 16:34
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序