大神请进org.hibernate.MappingException: Could not get constructor for org.hibernate

WGweb 2015-09-11 09:48:16
org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
怎么回事啊。。。



源码如下:

package entity;

import javax.imageio.spi.ServiceRegistry;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.junit.Test;

public class testStudent {

@Test
public void SchemaExpore() {
Configuration config = new Configuration().configure();
StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder().applySettings(config.getProperties());
StandardServiceRegistry standardServiceRegistry = standardServiceRegistryBuilder.build();
SessionFactory sessionFactory = config.buildSessionFactory(standardServiceRegistry);
SchemaExport export = new SchemaExport(config);
export.create(true, true);
}
}


我不加StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder().applySettings(config.getProperties());
StandardServiceRegistry standardServiceRegistry = standardServiceRegistryBuilder.build();
SessionFactory sessionFactory = config.buildSessionFactory(standardServiceRegistry);
的时候没事,,但加了就报这个错了,,求大神
...全文
2257 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanxi5339 2017-02-27
  • 打赏
  • 举报
回复
我也是这个问题,楼主解决了吗?
sinat_36659580 2016-11-26
  • 打赏
  • 举报
回复
实体类错了吧
lishiyuan30 2016-11-25
  • 打赏
  • 举报
回复
我也是这个问题 这是我的配置文件 <?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"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="connection.url"> jdbc:mysql://localhost/rent </property> <property name="connection.username">root</property> <property name="connection.password">123456</property> <property name="connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="myeclipse.connection.profile">rent</property> <mapping resource="com/hbtt/rent/entity/District.hbm.xml" /> <mapping resource="com/hbtt/rent/entity/Users.hbm.xml" /> <mapping resource="com/hbtt/rent/entity/Types.hbm.xml" /> <mapping resource="com/hbtt/rent/entity/House.hbm.xml" /> <mapping resource="com/hbtt/rent/entity/Street.hbm.xml" /> </session-factory> </hibernate-configuration> 这是我的HibernateSessionFactory package com.hbtt.rent.util; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; public class HibernateSessionFactory { private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>(); private static org.hibernate.SessionFactory sessionFactory; private static Configuration configuration = new Configuration(); private static ServiceRegistry serviceRegistry; static { try { configuration.configure(); serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); } catch (Exception e) { System.err.println("%%%% Error Creating SessionFactory %%%%"); e.printStackTrace(); } } private HibernateSessionFactory() { } public static Session getSession() throws HibernateException { Session session = (Session) threadLocal.get(); if (session == null || !session.isOpen()) { if (sessionFactory == null) { rebuildSessionFactory(); } session = (sessionFactory != null) ? sessionFactory.openSession() : null; threadLocal.set(session); } return session; } public static void rebuildSessionFactory() { try { configuration.configure(); serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); } catch (Exception e) { System.err.println("%%%% Error Creating SessionFactory %%%%"); e.printStackTrace(); } } public static void closeSession() throws HibernateException { Session session = (Session) threadLocal.get(); threadLocal.set(null); if (session != null) { session.close(); } } public static org.hibernate.SessionFactory getSessionFactory() { return sessionFactory; } public static Configuration getConfiguration() { return configuration; } }
心随自在飞 2015-09-15
  • 打赏
  • 举报
回复
实体对应的配置文件某个地方出问题了!
  • 打赏
  • 举报
回复
贴出你的配置文件,关于hibernate配置的
Cx_轩 2015-09-11
  • 打赏
  • 举报
回复
没有找到hebernate的构造器 是不是你配置hebernate对象的时候出现了问题 我觉得你配置有问题。 具体情况你这样是看不出来的。

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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