为什么hibernate无法根据model更新表?

hibernate的hbm2ddl.auto属性,设置成update后,无法根据model更新表!

异常日志

 INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@597db45e] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Hibernate: 

    create table DEPT (
        deptNo varchar2(255) not null,
        dname varchar2(255),
        time varchar2(255),
        primary key (deptNo)
    )
一月 24, 2017 10:11:30 上午 org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
    lCoordinator.process(SchemaManagementToolCoordinator.java:72)

Caused by: java.sql.SQLSyntaxErrorException: ORA-00955: 名称已由现有对象使用

    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059)
apper.execute(OracleStatementWrapper.java:334)
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
    ... 63 more

这是我的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- 指定连接数据库所用的驱动 -->
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <!-- 指定连接数据库的url,其中hibernate是本应用连接的数据库名 -->
        <property name="connection.url">jdbc:oracle:thin:@192.168.0.18:1521:qfy</property>
        <!-- 指定连接数据库的用户名 -->
        <property name="connection.username">MFJCIVAIRDEFDISCOUNTY</property>
        <!-- 指定连接数据库的密码 -->
        <property name="connection.password">QFY_2015</property>
        <!-- 指定连接池里最大连接数 -->
        <property name="hibernate.c3p0.max_size">20</property>
        <!-- 指定连接池里最小连接数 -->
        <property name="hibernate.c3p0.min_size">1</property>
        <!-- 指定连接池里连接的超时时长 -->
        <property name="hibernate.c3p0.timeout">5000</property>
        <!-- 指定连接池里最大缓存多少个Statement对象 -->
        <property name="hibernate.c3p0.max_statements">100</property>
        <property name="hibernate.c3p0.idle_test_period">3000</property>
        <property name="hibernate.c3p0.acquire_increment">2</property>
        <property name="hibernate.c3p0.validate">true</property>
        <!-- 指定数据库方言 -->
        <property name="dialect">org.hibernate.dialect.OracleDialect</property>
        <!-- 根据需要自动创建数据表 -->
        <property name="hbm2ddl.auto">update</property><!--① -->
        <!-- 显示Hibernate持久化操作所生成的SQL -->
        <property name="show_sql">true</property>
        <!-- 将SQL脚本进行格式化后再输出 -->
        <property name="hibernate.format_sql">true</property>
        <!-- 避免这个错误信息Disabling contextual LOB creation as createClob() method threw error :java.lang.reflect.InvocationTargetException -->
        <property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
    </session-factory>
</hibernate-configuration> 

2个回答

换成在spring文件里面写hibernate的属性后,就好了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Hibernate中如何实现一个model和多个表关联

RT, 如何能不创建额外的对象的前提下,把一个对象拆到多个表中? [b]问题补充:[/b] 示例model [code="java"] public class ModelA{ private long id; private String description = ""; private String title = ""; ..... } [/code] 现在想把description独立到另外的表中,如何修改映射文件 [code="java"] <id name="id" type="java.lang.Long"> <column name="id" /> <generator class="assigned"></generator> </id> <property name="description" type="java.lang.String"> <column name="description" sql-type="MediumBLOB"/> </property> [/code]

使用hibernate tools反向生成model和配置文件,一定要hbm.xml文件吗?

我以前使用的是myeclipse,里面有一个方向生成hibernate配置文件和model的工具,是不需要hibernate.hbm.xml文件的, 由于myeclipse的速度太慢,我现在用的是eclipse,安装了hibernate tools,但是在使用hibernate tools反向生成配置文件和model的时候, 需要新建一个hibernate.hbm.xml文件,我的项目使用的架构是ssh, hibernate已经交给了spring管理了,已经没有hibernate.hbm.xml文件了, 请问这种情况下该如何处理?

使用Hibernate 如何把多个表的数据查询到一个POJO

http://blog.csdn.net/yangqicong/article/details/6910740 看了你这篇文章后,有一个疑问. 如果写SQL把 A B 表关联,查询出A 表全部字段和B表一个字段 别名为A 表里一个不被hibernate 创建到数据库表的字段, 也就是说查询出的字段都和A POJO 字段一一对应. 那么我怎么把查询结果放到A POJO 去呢? 然后发现可以尝试 query.setResultTransformer(Transformers.aliasToBean(SM_Power.class)); 但是这样写又有新问题,MYSQL 没有Long类型,但是POJO 里面有,然后hibernate就会报错. query.addScalar("id", Hibernate.LONG); 这样指定了就不会类型错误,但是这样只能查询出一个字段,如果很多个字段那不就搞死人了. 所以以上总结后有2个方案. 1 有没有除了代码1块 的处理结果的其他方法 2 有没有和代码2块 功能相反的方法,除了指定的其他的按照 代码块1的执行转换. 不知道你们是怎么处理的,因为才接触hibernate ,所以请大伙能给个更好的方法.

hibernate表记录更新引发连接表数据被删问题

<p>我的项目中有两个表document、level,它们之间通过连接表实现关联,映射文件如下:</p> <p>表document</p> <pre name="code" class="xml">&lt;hibernate-mapping&gt; &lt;class name="com.unionmon.knowledge.model.KleDocument" table="KLE_DOCUMENT" schema="UFLOW"&gt; &lt;id name="kleDocumentId" type="java.lang.Long"&gt; &lt;column name="KLE_DOCUMENT_ID" precision="22" scale="0" /&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;join table="KLE_DOC_SECRET_UNION" optional="true"&gt; &lt;key column="KLE_DOCUMENT_ID" unique="true"/&gt; &lt;many-to-one name="secretLev" column="KLE_SECRET_LEVEL_ID" not-null="true"/&gt; &lt;/join&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt;</pre> <p> 表level:</p> <pre name="code" class="xml">&lt;hibernate-mapping&gt; &lt;class name="com.unionmon.knowledge.model.KleSecretLevel" table="KLE_SECRET_LEVEL" schema="UFLOW"&gt; &lt;id name="kleSecretLevelId" type="java.lang.Long"&gt; &lt;column name="KLE_SECRET_LEVEL_ID" precision="22" scale="0" /&gt; &lt;generator class="native"&gt;&lt;/generator&gt; &lt;/id&gt; &lt;set name="kleDocs" table="KLE_DOC_SECRET_UNION"&gt; &lt;key column="KLE_SECRET_LEVEL_ID"/&gt; &lt;many-to-many column="KLE_DOCUMENT_ID" class="com.unionmon.knowledge.model.KleDocument"/&gt; &lt;/set&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt;</pre> <p> 表document和level的连接表</p> <pre name="code" class="xml">&lt;hibernate-mapping package="com.unionmon.knowledge.model"&gt; &lt;class name="KleDocSecretUnion" table="KLE_DOC_SECRET_UNION" schema="UFLOW"&gt; &lt;many-to-one name="kleSecretLevel" class="KleSecretLevel" fetch="select"&gt; &lt;column name="KLE_SECRET_LEVEL_ID" precision="22" scale="0" /&gt; &lt;/many-to-one&gt; &lt;many-to-one name="kleDocument" class="KleDocument" fetch="select"&gt; &lt;column name="KLE_DOCUMENT_ID" precision="22" scale="0" /&gt; &lt;/many-to-one&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt;</pre> <p> 问题出现在当我更新level表中的某条记录时(比如该记录编号为level_id),发现hibernate有一条语句删除了连接表中所有KLE_SECRET_LEVEL_ID字段值为level_id的记录,我的service层代码如下:</p> <pre name="code" class="java"> public String editLevel(KleSecretLevel new_level, long id,long doc_id){ new_level.setKleDocumentId(doc_id); new_level.setKleSecretLevelId(id); this.secretDao.save(new_level); return "{success: true, msg: '修改成功 '}"; }</pre> <p> </p> <p> dao层代码如下:</p> <pre name="code" class="java">public T save(T object) { return (T) super.getHibernateTemplate().merge(object); }</pre> <p> </p> <p>我查阅了hibernate的官方文档和对此错误进行了Google,实在找不到程序不妥的地方,烦请各位解下小弟疑惑。</p>

hibernate在model中注解的主键更改,级联操作怎么改

主表product @GeneratedValue(strategy = GenerationType.AUTO) public int getID() { return ID; } public void setID(int iD) { ID = iD; } @Id public String getProductCode() { return ProductCode; } public void setProductCode(String productCode) { ProductCode = productCode; } . . . @OneToMany(targetEntity = ProductChannel.class, mappedBy = "product", cascade = CascadeType.ALL) @JoinColumn(name = "ProductCode", updatable = false) public Set<ProductChannel> getProductChannelSet() { return productChannelSet; } public void setProductChannelSet(Set<ProductChannel> productChannelSet) { this.productChannelSet = productChannelSet; } @OneToMany(targetEntity = ProductPriority.class, mappedBy = "product", cascade = CascadeType.ALL) @JoinColumn(name = "ProductCode", updatable = false) public Set<ProductPriority> getProductPrioritySet() { return productPrioritySet; } public void setProductPrioritySet(Set<ProductPriority> productPrioritySet) { this.productPrioritySet = productPrioritySet; } 表ProductChannel @Id @GeneratedValue(strategy = GenerationType.AUTO) public int getID() { return ID; } public void setID(int iD) { ID = iD; } @Transient public String getProductCode() { return ProductCode; } public void setProductCode(String productCode) { ProductCode = productCode; } @ManyToOne(targetEntity = Product.class, cascade = CascadeType.PERSIST) @Fetch(FetchMode.JOIN) @JoinColumn(name = "ProductCode") public Product getProduct() { return product; } public void setProduct(Product product) { this.product = product; } 表ProductPriority @Id @GeneratedValue(strategy = GenerationType.AUTO) public int getID() { return ID; } public void setID(int iD) { ID = iD; } @Transient public String getProductCode() { return ProductCode; } public void setProductCode(String productCode) { ProductCode = productCode; } @ManyToOne(targetEntity = Product.class, cascade = CascadeType.PERSIST) @Fetch(FetchMode.JOIN) @JoinColumn(name = "ProductCode") public Product getProduct() { return product; } public void setProduct(Product product) { this.product = product; } 现在是要把表product的主键设为ID,ProductCode设为唯一键,外键都不变,下面两个表需要怎么改呢

hibernate 框架运行时提示

log4j:WARN No appenders could be found for logger (org.jboss.logging). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.OracleDatabaseMetaData.getDatabaseMajorVersion()I at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:80) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) 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.cfg.Configuration.buildSessionFactory(Configuration.java:692) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724) at cn.zlkj.test.Test.main(Test.java:19)

hibernate string型为主键问题

数据库为mysql,主键设为string型的fileName,然后在hbm.xml中设置<id> <generator class="assigned"> 到session.save()时出现下列异常: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.demo.model.UserFiles at org.hibernate.id.Assigned.generate(Assigned.java:33) at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99) (下略) 基本上就是存储时主键fileName这个字段没有默认值,无法保存;看来是fileName没有被识别出来,但是程序中我都明明.SetFileName(). 还有hibernate操作int型主键时就没问题,对string型主键不知应该如何处理? [b]问题补充:[/b] to ag_sherry 那是不是数据表还必须设置一个id字段?hibernate会自动为你生成一个32位的无重复的id,不理解,感觉string还不是主键,反倒这个无重复的id是主键了

Hibernate删除主从表的问题

我现在用SSH框架做个小项目.现在遇到这样的问题,现在有五张表,一张人员表(users),一张文件表(files),一张文件操作类型表(fileOperations),一张文件夹表(folder)一张中间表(user_file_operation),中间表有三个字段(userId,fileId,operationId),这三个字段都为为外键,userId,fileId,operationId分别为三张表的主键.因为是多表关联,在pojo中所以我引申了一个类,类名为BarSnafu,这个类包含其他两个类的字段,分别为(private Users user;private fileOperations fileOPeration;)并都get和set方法, 我的file类包含有BarSnafuSet集合. <set name="BarsnafusSet" table="user_file_operation" cascade="save-update"> <key column="file_id" /> <composite-element class="com.linkey.fms.common.model.pojo.BarSnafu"> <many-to-one cascade="save-update" name="fileOperation" column="operationId" class="com.linkey.fms.common.model.pojo.Fileoperations" /> <many-to-one cascade="save-update" name="user" column="userId" class="com.linkey.fms.common.model.pojo.Users" /> </composite-element> </set> 其他User类和FileOperation未配Set集合,因为只有新建文件时才会选择用户和操作类型,而新建用户和操作类型是不用选择文件的,也就是说这种关系是单向的. 现在我要增加文件,因为一个文件包含多个操作类型和用户,所以我是这样做的,Files tFile=new Files(); tFile.setFileName("11");tFile.setFileTitle("11");tFile.setFolder(folder);Set set=new HashSet(); Users user1=new User();FileOperations operation1=new FileOperations();BarSnafu bar1=new BarSnafu(); bar1.setUser(user1);bar2.setFileOperation(operation1);set.add(bar1); 依次类推,我在set集合里加了bar2,bar3等,然后在tFile.setBarSnafuSet(set);然后调用Hibernate的Save()方法,此时报了 a different object with the same identifier value was already associated with the session异常,这个问题已经解决,我是调用Hibernate中的merge()方法. 然后我在页面显示了某一文件夹的所有文件(只是显示该文件夹的文件),我选了该文件夹下的部分文件,点击删除,用的是Hibernate中的deleteAll(list)方法,而且我在Action已经把所选择的文件放在一个List里面.按理说我只是要删除我所选择的文件,但是Hibernate却做了一件我怎么也搞不明白的事,它先删除我所选择的文件,然后找到该文件所在的文件夹,然后再删除该文件夹下的所有文件,然后再删除该文件夹.我写了一个测试类,代码如下 [color=red] public class SysFileServiceTest extends BaseTest{ private FileFrameService fileService; private FolderFrameService folderService; private FileOperationFrameService fileOperationService; private SysUserService sysUserService; @Before public void setUp() { fileService = (FileFrameService) factory.getBean("fileService"); folderService = (FolderFrameService) factory.getBean("folderService"); fileOperationService = (FileOperationFrameService) factory.getBean("fileOperationService"); sysUserService = (SysUserService) factory.getBean("sysUserService"); } @Test public void deleteFile() { TSysFile tFile1=fileService.findFileByFileId("11111"); TSysFile tFile2=fileService.findFileByFileId("22222"); List<TSysFile> list=new ArrayList<TSysFile>(); list.add(tFile1); list.add(tFile2); boolean flag=fileService.deleteFileBatch(list); System.out.println(flag); } } [/color] 测试类没有通过,报的确是a different object with the same identifier value was already associated with the session这个异常. 有谁能帮我分析下这是什么原因,怎么来解决这个问题.

Hibernate多表查询

<div class="iteye-blog-content-contain" style="font-size: 14px;"> <p>public PageModel getPage(int currentPage, int pageSize) { String hql = "from Orders,Users,Orderstate where Orders.clientid = Users.userid and Orders.progress = Orderstate.stateid"; String count = "select count(*) from Orders"; PageModel pageModel = this.getPage(hql, count, currentPage, pageSize); return pageModel; } 项目中使用的是hibernate框架,要进行多表查询,在DAO类方法中是这么写的,但是运行项目出现了错误,怎么解决,这个语句在数据库中可以执行,hibernate中会报错</p> <pre name="code" class="java">Struts Problem Report Struts has detected an unhandled exception: Messages: Invalid path: 'null.clientid' [from com.scan918.printerordersystem.model.Orders,com.scan918.printerordersystem.model.Users,com.scan918.printerordersystem.model.Orderstate where Orders.clientid = Users.userid and Orders.progress = Orderstate.stateid] Invalid path: 'null.clientid' [from com.scan918.printerordersystem.model.Orders,com.scan918.printerordersystem.model.Users,com.scan918.printerordersystem.model.Orderstate where Orders.clientid = Users.userid and Orders.progress = Orderstate.stateid]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: Invalid path: 'null.clientid' [from com.scan918.printerordersystem.model.Orders,com.scan918.printerordersystem.model.Users,com.scan918.printerordersystem.model.Orderstate where Orders.clientid = Users.userid and Orders.progress = Orderstate.stateid] File: org/hibernate/hql/ast/QuerySyntaxException.java Line number: 54 Stacktraces org.springframework.orm.hibernate3.HibernateQueryException: Invalid path: 'null.clientid' [from com.scan918.printerordersystem.model.Orders,com.scan918.printerordersystem.model.Users,com.scan918.printerordersystem.model.Orderstate where Orders.clientid = Users.userid and Orders.progress = Orderstate.stateid]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: Invalid path: 'null.clientid' [from com.scan918.printerordersystem.model.Orders,com.scan918.printerordersystem.model.Users,com.scan918.printerordersystem.model.Orderstate where Orders.clientid = Users.userid and Orders.progress = Orderstate.stateid] org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:657) org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424) org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:343) com.scan918.printerordersystem.dao.impl.BaseDAO.pageQuery(BaseDAO.java:301) com.scan918.printerordersystem.dao.impl.BaseDAO.getPage(BaseDAO.java:323) com.scan918.printerordersystem.dao.impl.OrdersDAOImpl.getPage(OrdersDAOImpl.java:21) com.scan918.printerordersystem.service.impl.OrderServiceImpl.getPage(OrderServiceImpl.java:26) com.scan918.printerordersystem.action.admin.AOrderAction.getPage(AOrderAction.java:63) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:601) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) java.lang.Thread.run(Thread.java:722) org.hibernate.hql.ast.QuerySyntaxException: Invalid path: 'null.clientid' [from com.scan918.printerordersystem.model.Orders,com.scan918.printerordersystem.model.Users,com.scan918.printerordersystem.model.Orderstate where Orders.clientid = Users.userid and Orders.progress = Orderstate.stateid] org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54) org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47) org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82) org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261) org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185) org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:101) org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:80) org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94) org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135) org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:601) org.springframework.orm.hibernate3.HibernateTemplate$CloseSuppressingInvocationHandler.invoke(HibernateTemplate.java:1293) $Proxy12.createQuery(Unknown Source) com.scan918.printerordersystem.dao.impl.BaseDAO$6.doInHibernate(BaseDAO.java:306) org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419) org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:343) com.scan918.printerordersystem.dao.impl.BaseDAO.pageQuery(BaseDAO.java:301) com.scan918.printerordersystem.dao.impl.BaseDAO.getPage(BaseDAO.java:323) com.scan918.printerordersystem.dao.impl.OrdersDAOImpl.getPage(OrdersDAOImpl.java:21) com.scan918.printerordersystem.service.impl.OrderServiceImpl.getPage(OrderServiceImpl.java:26) com.scan918.printerordersystem.action.admin.AOrderAction.getPage(AOrderAction.java:63) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:601) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) java.lang.Thread.run(Thread.java:722) You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set: struts.devMode=false in your WEB-INF/classes/struts.properties file.</pre> <p> </p> </div>

hibernate中报SessionFactory为空

这是我的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="connection.username">root</property> <property name="connection.password">195824</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">idbc:mysql:///testHibernateTable<!-- ?useUnicode=true&amp;characterEncoding:UTF-8 --></property> <property name="javax.persistence.validation.mode">none</property> <!-- 数据库操作语句的显示 --> <property name="show_sql">true</property> <!-- 将数据库的输出是否排版 --> <property name="format_sql">true</property> <!-- 数据表的生成策略 有四个create:传建一个新的数据表,若存在则删除存在的在创建一个新的; update:更新原有表; creat_drop:先创建再删除; validate:对原来的表结构进行验证,若不同创建一个新的表--> <property name="hbm2ddl.auto">create</property> <!-- 数据表的方言 --> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <mapping resource="com/test/hibernate/Student.hbm.xml"/> </session-factory> </hibernate-configuration> 这是我映射的Student.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"> <!-- Generated 2017-7-17 23:09:26 by Hibernate Tools 3.5.0.Final --> <hibernate-mapping> <class name="com.test.Hibernate.Student" table="STUDENT"> <id name="id" type="int"> <column name="ID" /> <generator class="assigned" /> </id> <property name="name" type="java.lang.String"> <column name="NAME" /> </property> <property name="sex" type="java.lang.String"> <column name="SEX" /> </property> <property name="age" type="int"> <column name="AGE" /> </property> </class> </hibernate-mapping> 这是我测试类的内容 package com.test.Junit; 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.After; import org.junit.Before; import org.junit.Test; import com.test.hibernate.Student; public class TestHiber { /** * 获得关系映射对象文件 */ private SessionFactory sessionFactory=null; /** *类似于JDBC中的Connection */ private Session session; /** * 获得事物对象 */ private Transaction transaction; private Configuration config; @Before public void init(){ //读取配置文档hibernate.cfg.xml文件 config = new Configuration().configure("hibernate.cfg.xml"); //创建服务注册对象 ServiceRegistry serviceRegistry = new ServiceRegistryBuilder(). applySettings(config.getProperties()).buildServiceRegistry(); //创建会话工厂对象 sessionFactory = config.buildSessionFactory(serviceRegistry); //会话对象 session = sessionFactory.getCurrentSession(); //打开事物 transaction = session.beginTransaction(); } @After public void destory(){ transaction.commit();//提交事务 session.close();//关闭会话 sessionFactory.close();//关闭会话工厂对象 } @Test public void test() { Student student = new Student(1, "Minions", "sex", 10); session.save(student); } } 这是junit报错的内容 java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.hibernate.search.hcore.impl.HibernateSearchIntegrator could not be instantiated at java.util.ServiceLoader.fail(ServiceLoader.java:232) at java.util.ServiceLoader.access$100(ServiceLoader.java:185) at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384) at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404) at java.util.ServiceLoader$1.next(ServiceLoader.java:480) at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:233) at org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:53) at org.hibernate.service.internal.BootstrapServiceRegistryImpl.<init>(BootstrapServiceRegistryImpl.java:80) at org.hibernate.service.internal.BootstrapServiceRegistryImpl.<init>(BootstrapServiceRegistryImpl.java:57) at org.hibernate.service.ServiceRegistryBuilder.<init>(ServiceRegistryBuilder.java:76) at com.test.Junit.TestHiber.init(TestHiber.java:34) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: java.lang.NoClassDefFoundError: org/apache/lucene/index/CorruptIndexException at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at org.jboss.logging.Logger.getMessageLogger(Logger.java:2248) at org.jboss.logging.Logger.getMessageLogger(Logger.java:2214) at org.hibernate.search.util.logging.impl.LoggerFactory.make(LoggerFactory.java:37) at org.hibernate.search.hcore.impl.HibernateSearchIntegrator.<clinit>(HibernateSearchIntegrator.java:49) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at java.lang.Class.newInstance(Class.java:442) at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380) ... 32 more Caused by: java.lang.ClassNotFoundException: org.apache.lucene.index.CorruptIndexException at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 44 more java.lang.NullPointerException at com.test.Junit.TestHiber.destory(TestHiber.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 以下是控制台的报错内容 INFO: HHH000221: Reading mappings from resource: com/test/hibernate/Student.hbm.xml 七月 19, 2017 10:29:01 下午 org.hibernate.cfg.Configuration doConfigure INFO: HHH000041: Configured SessionFactory: null

怎样自动生成基于注释的model

大家好,问下怎么样能用 eclipse 或 myEclipse 生成 基于注释的 model,工程里用过,但是不知道怎么生成的.

测试hibernate注解时出现错误

org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:267) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) 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:179) at com.entity.TestStudents.testShemaExport(TestStudents.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:257) ... 36 more

Hibernate 多对多 查询得到的关联集合对象为空

org.springframework.dao.DataIntegrityViolationException: could not insert collection rows: [org.model.Xsb.kcs#081101 ]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert collection rows: [org.model.Xsb.kcs#081101 ] org.hibernate.exception.ConstraintViolationException: could not insert collection rows: [org.model.Xsb.kcs#081101 ] com.microsoft.sqlserver.jdbc.SQLServerException: 违反了 PRIMARY KEY 约束 'PK_XS_KCB'。不能在对象 'dbo.XS_KCB' 中插入重复键。 后来我又在主控表里加了inverse=“true”但由学生get()得到的关联set对象kcs为空

springboot 配置hibernate 开始使用的是mysql,都正常,但是换成Oracle后总是创建表。

springboot 配置hibernate 开始使用的是mysql,都正常,但是换成Oracle后总是创建表。所以后台报如下表重复错误。这是为什么呀?应该是如果发现表已经有的话不应该再创建才对,请帮我看下哪里配置错了。 再详细说明下我的场景: 数据库映射的对象Product。 第一次系统启动肯定会创建一个,因为数据库中是没有这个表,然后系统重启或者再次启动,正常来讲,Product对象没有改过,数据库表也存在,hibernate不应该再创建,但是目前就是再创建,所以报表名已经有的错误。 ``` Caused by: java.sql.SQLSyntaxErrorException: ORA-00955: 名称已由现有对象使用 at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447) ~[ojdbc-6.6.0.jar:11.2.0.4.0] at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) ~[ojdbc-6.6.0.jar:11.2.0.4.0] at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951) ~[ojdbc-6.6.0.jar:11.2.0.4.0] ``` ``` server: port: 8001 spring: application: name: DEMO_TEST #f服务名称定义 datasource: type: com.alibaba.druid.pool.DruidDataSource # 当前数据源操作类型 #driver-class-name: com.mysql.cj.jdbc.Driver # mysql驱动包 driver-class-name: oracle.jdbc.driver.OracleDriver #url: jdbc:mysql://127.0.0.1:3306/rd_plm?serverTimezone=GMT%2B8 # 数据库名称 url: jdbc:oracle:thin:@127.0.0.1:1521/DD username: root password: root dbcp2: min-idle: 5 # 数据库连接池的最小维持连接数 initial-size: 5 # 初始化连接数 max-total: 5 # 最大连接数 max-wait-millis: 150 # 等待连接获取的最大超时时间 jpa: hibernate: naming: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl ddl-auto: update show-sql: true properties: hibernate: #dialect: org.hibernate.dialect.MariaDBDialect dialect: org.hibernate.dialect.OracleDialect current_session_context_class: org.springframework.orm.hibernate5.SpringSessionContext #database: MYSQL database: oracle open-in-view: true ```

hibernate注解 外键是另一表的非主键问题!

![图片说明](https://img-ask.csdn.net/upload/201508/06/1438846505_322207.png) ![图片说明](https://img-ask.csdn.net/upload/201508/06/1438846461_547656.png) 求教!!!???!!!!!

hibernate 级联保存明细时,外键没有被赋值

hibernate jpa 配置model,一对多的关系,保存主表时级联保存子表,子表中的主表外键为空。难道要先保存主表,然后手动去赋子表的外键?这还叫级联保存吗。求解!!! 例如: [code="java"] public class Order extends AbstractNsSimpleModel { private static final long serialVersionUID = -3227571634593243399L; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "order", orphanRemoval = true) private Set<OrderItem> orderItems = new HashSet<OrderItem>(); public Set<OrderItem> getOrderItems() { return orderItems; } public void setOrderItems(Set<OrderItem> orderItems) { this.orderItems = orderItems; } } [/code] [code="java"] public class OrderItem extends AbstractNsSimpleModel { private static final long serialVersionUID = -7120458190166247286L; @Column(name = "ORDER_ID", insertable = false, updatable = false, nullable = false) private Long orderId; @ManyToOne(fetch = FetchType.EAGER, optional = false) @JoinColumn(name = "ORDER_ID", referencedColumnName = "ID") private Order order; public Long getOrderId() { return orderId; } public void setOrderId(Long orderId) { this.orderId = orderId; } public Order getOrder() { return order; } public void setOrder(Order order) { this.order = order; } } [/code] 保存order时,级联保存orderItem,orderItem是被保存了,但是外键orderId为null。

hibernate search 字母根据注解配置的类的字段名获取配置好的 文档域名

hibernate search 字母根据注解配置的类的字段名获取配置好的 文档域名 @Indexed(index = "search_QbXtbaSj") public class QbXtbaSj {//协同办案系统-手机 @Id @Column(name="OBJECTID") @DocumentId private Long id; @Column(name="BRAND") @Field(name = "QbXtbaSj_BRAND", index = Index.TOKENIZED, store = Store.YES) private String BRAND; //品牌 @Column(name="MODEL") @Field(name = "QbXtbaSj_MODEL", index = Index.TOKENIZED, store = Store.YES) private String MODEL; //型号 @Column(name="TELNO") @Field(name = "QbXtbaSj_TELNO", index = Index.TOKENIZED, store = Store.YES) private String TELNO; //电话号码 @Column(name="IMEI") @Field(name = "QbXtbaSj_IMEI", index = Index.TOKENIZED, store = Store.YES) private String IMEI; //IMEI串号 @Column(name="OWNERNAME") @Field(name = "QbXtbaSj_OWNERNAME", index = Index.TOKENIZED, store = Store.YES) private String OWNERNAME; //机主姓名 @Column(name="ETLDATE",nullable = true) @Field(name = "QbXtbaSj_ETLDATE", index = Index.TOKENIZED, store = Store.YES) @Temporal(TemporalType.TIMESTAMP) private Date ETLDATE; //抽取时间 比如 根据“BRAND” 获得配置的“QbXtbaSj_BRAND”? hibernate search有没有相关api 帮帮兄弟我

hibernate+mysql问题

<p>UserModel.java</p> <p>package cn.javass.model;</p> <p>public class UserModel {<br> private Integer uuid;<br> private String name;<br> private Integer age;<br> public Integer getUuid() {<br>  return uuid;<br> }<br> public void setUuid(Integer uuid) {<br>  this.uuid = uuid;<br> }<br> public String getName() {<br>  return name;<br> }<br> public void setName(String name) {<br>  this.name = name;<br> }<br> public Integer getAge() {<br>  return age;<br> }<br> public void setAge(Integer age) {<br>  this.age = age;<br> }<br> <br>}</p> <p> </p> <p>UserModel.hbm.xml(我想配uuid自增)</p> <p>&lt;?xml version="1.0"?&gt;<br>&lt;!DOCTYPE hibernate-mapping PUBLIC <br> "-//Hibernate/Hibernate Mapping DTD 3.0//EN"<br> "<a href="http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd</a>"&gt;<br>&lt;hibernate-mapping <br> package="org.hibernate.auction"&gt;<br> &lt;class name="cn.javass.model.UserModel" table="tbl_user"&gt;<br>  &lt;id name="uuid" unsaved-value="0"&gt; <br>   &lt;generator class="increment"/&gt;<br>  &lt;/id&gt;<br>  &lt;property name="name"/&gt;<br>  &lt;property name="age"/&gt;<br> &lt;/class&gt;<br>  <br>&lt;/hibernate-mapping&gt;</p> <p> </p> <p>hibernate.cfg.xml</p> <p> </p> <p>&lt;?xml version='1.0' encoding='UTF-8'?&gt;<br>&lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "<a href="http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd</a>"&gt;</p> <p>&lt;hibernate-configuration&gt;</p> <p> &lt;session-factory&gt;<br>  <br>  &lt;property name="hibernate.connection.driver_class"&gt;org.gjt.mm.mysql.Driver&lt;/property&gt;<br>  &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/dhwebnms&lt;/property&gt;<br>  &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;<br>  &lt;property name="hibernate.connection.password"&gt;xxxxxx&lt;/property&gt;<br>  <br>  &lt;property name="show_sql"&gt;true&lt;/property&gt;<br>  &lt;property name="dialect"&gt;net.sf.hibernate.dialect.MySQLDialect&lt;/property&gt;<br>  &lt;mapping resource="cn/javass/model/UserModel.hbm.xml"/&gt;  <br> &lt;/session-factory&gt;</p> <p>&lt;/hibernate-configuration&gt;</p> <p> </p> <p>public class UserDao {<br> public boolean  create(UserModel um,SessionFactory sf){<br>  Session se=null;<br>  Transaction tx=null;<br>  try{<br>   se=sf.openSession();<br>   tx=se.beginTransaction();<br>   se.save(um);<br>   tx.commit();<br>   se.close();<br>  }catch(Exception e){<br>   return false;<br>  }<br>  <br>  return true;<br>  <br> }<br> <br> public List getAll(){<br>  return null;<br> }<br> <br> public static void main(String[] args) {<br>  SessionFactory sessionFactory=null;<br>  try {<br>   sessionFactory=new Configuration().configure().buildSessionFactory();<br>   UserDao ud=new UserDao();<br>   UserModel um=new UserModel();<br>   um.setName("xyb");<br>   um.setAge(new Integer(10));<br>   ud.create(um, sessionFactory);<br>  } catch (HibernateException e) {<br>   e.printStackTrace();<br>  }<br>  <br> }<br>}</p> <p> </p> <p> </p> <p>运行后就报错,</p> <p>net.sf.hibernate.MappingException: Error reading resource: cn/javass/model/UserModel.hbm.xml<br> at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)<br> at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:990)<br> at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:946)<br> at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:874)<br> at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:860)<br> at cn.javass.dao.UserDao.main(UserDao.java:38)<br>Caused by: net.sf.hibernate.MappingException: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect<br> at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:293)<br> at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:333)<br> ... 5 more<br>Caused by: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect<br> at org.dom4j.io.SAXReader.read(SAXReader.java:358)<br> at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:283)<br> ... 6 more</p> <p> </p> <p>我不知道我的UserModel.hbm.xml的配制文件哪个写错了,请大家帮我看看.谢谢!</p> <p> </p><br /><strong>问题补充:</strong><br />没有听明白<br /><strong>问题补充:</strong><br />两位兄弟,我用的是hibernate2,pan_java回答的肯定不对,但是hibernate2怎么去配的就不知道了,请指教<br /><strong>问题补充:</strong><br />兄弟们: <br />hibernate.cfg.xml <br />&lt;?xml version="1.0" encoding="utf-8"?&gt;&nbsp;&nbsp; <br />&lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN"&nbsp;&nbsp;&nbsp;&nbsp; <br />"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"&gt;&nbsp;&nbsp; <br />&lt;hibernate-configuration&gt; <br />&nbsp;&nbsp;&nbsp; &lt;session-factory&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="dialect"&gt;net.sf.hibernate.dialect.MySQLDialect&lt;/property&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="connection.driver_class"&gt;org.gjt.mm.mysql.Driver&lt;/property&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="connection.username"&gt;root&lt;/property&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="connection.password"&gt;xybxyb&lt;/property&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/dhwebnms&lt;/property&gt; <br /> <br /> &lt;property name="show_sql"&gt;true&lt;/property&gt; <br />&nbsp;&nbsp;&nbsp; &lt;/session-factory&gt; <br /> <br />&lt;/hibernate-configuration&gt; <br /> <br />就这样,然后我去SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory(); <br />运行结果是; <br />net.sf.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml <br /> at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:935) <br /> at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:874) <br /> at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:860) <br /> at cn.javass.dao.UserDao.main(UserDao.java:41) <br />Caused by: net.sf.hibernate.MappingException: invalid configuration <br /> at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:931) <br /> ... 3 more <br />Caused by: org.xml.sax.SAXParseException: The content of element type "session-factory" is incomplete, it must match "(property*,mapping+,(class-cache|collection-cache|jcs-class-cache|jcs-collection-cache)*)". <br /> at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) <br /> at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) <br /> at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) <br /> at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) <br /> at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source) <br /> at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source) <br /> at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source) <br /> at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) <br /> at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) <br /> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) <br /> at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source) <br /> at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) <br /> at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) <br /> at org.dom4j.io.SAXReader.read(SAXReader.java:339) <br /> at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:930) <br /> ... 3 more <br />请指点 <br /> <br /><br /><strong>问题补充:</strong><br />谢谢各位的帮忙,但是现在为什么插不进数据呀,运行不抛异常,数据库里面没有数据 <br />&lt;?xml version="1.0" encoding="utf-8"?&gt;&nbsp;&nbsp; <br />&lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN"&nbsp;&nbsp;&nbsp;&nbsp; <br />"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"&gt;&nbsp;&nbsp; <br />&lt;hibernate-configuration&gt; <br />&nbsp;&nbsp;&nbsp; &lt;session-factory&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="dialect"&gt;net.sf.hibernate.dialect.MySQLDialect&lt;/property&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="connection.driver_class"&gt;org.gjt.mm.mysql.Driver&lt;/property&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="connection.username"&gt;root&lt;/property&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="connection.password"&gt;xxxxxx&lt;/property&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/dhwebnms&lt;/property&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &lt;property name="connection.pool.size"&gt;1&lt;/property&gt; <br /> &lt;property name="statement_cache.size"&gt;25&lt;/property&gt; <br /> &lt;property name="jdbc.fetch_size"&gt;50&lt;/property&gt; <br /> &lt;property name="jdbc.batch_size"&gt;30&lt;/property&gt; <br /> <br /> &lt;property name="show_sql"&gt;true&lt;/property&gt; <br /> &lt;mapping resource="cn/javass/model/UserModel.hbm.xml" /&gt; <br /> <br />&nbsp;&nbsp;&nbsp; &lt;/session-factory&gt; <br /> <br />&lt;/hibernate-configuration&gt; <br /> <br /> <br />UserModel.hbm.xml <br />&lt;?xml version="1.0"?&gt; <br />&lt;!DOCTYPE hibernate-mapping PUBLIC <br />"-//Hibernate/Hibernate Mapping DTD 2.0//EN" <br />"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"&gt; <br />&lt;hibernate-mapping <br />package="org.hibernate.auction"&gt; <br />&lt;class name="cn.javass.model.UserModel" table="tbl_user"&gt; <br />&nbsp; &lt;id name="uuid" type="java.lang.Integer"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;column name="uuid" /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;generator class="native" /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/id&gt; <br />&nbsp; &lt;property name="name"/&gt; <br />&nbsp; &lt;property name="age"/&gt; <br />&lt;/class&gt; <br />&nbsp; <br />&lt;/hibernate-mapping&gt; <br />运行的语句 <br />SessionFactory sessionFactory=null; <br /> try { <br /> <br /> sessionFactory=new Configuration().configure().buildSessionFactory(); <br /> UserDao ud=new UserDao(); <br /> UserModel um=new UserModel(); <br /> um.setName("xyb"); <br /> um.setAge(new Integer(10)); <br /> ud.create(um, sessionFactory); <br /> } catch (HibernateException e) { <br /> e.printStackTrace(); <br /> } <br />数据库中没有值<br /><strong>问题补充:</strong><br />不好意思,我说的不报错,其实错:错误为 <br />se===&gt;net.sf.hibernate.impl.SessionImpl@157aa53 <br />net.sf.hibernate.JDBCException: Cannot open connection <br /> at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:281) <br /> at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3302) <br /> at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3282) <br /> at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40) <br /> at net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:19) <br /> at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2227) <br /> at cn.javass.dao.UserDao.create(UserDao.java:22) <br /> at cn.javass.dao.UserDao.main(UserDao.java:48) <br />Caused by: java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306? <br /> at org.gjt.mm.mysql.MysqlIO.init(MysqlIO.java:327) <br /> at org.gjt.mm.mysql.Connection.connectionInit(Connection.java:261) <br /> at org.gjt.mm.mysql.jdbc2.Connection.connectionInit(Connection.java:89) <br /> at org.gjt.mm.mysql.Driver.connect(Driver.java:167) <br /> at java.sql.DriverManager.getConnection(DriverManager.java:525) <br /> at java.sql.DriverManager.getConnection(DriverManager.java:140) <br /> at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:101) <br /> at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:278) <br /> ... 7 more <br /><br /><strong>问题补充:</strong><br />我启动了mysql,也开启了事务 <br />public class UserDao { <br /> public boolean&nbsp; create(UserModel um,SessionFactory sf){ <br /> Session se=null; <br /> Transaction tx=null; <br /> try{ <br /> se=sf.openSession(); <br /> System.out.println("se===&gt;"+se); <br /> tx=se.beginTransaction(); <br /> se.save(um); <br /> tx.commit(); <br /> se.close(); <br /> }catch(Exception e){ <br /> e.printStackTrace(); <br /> return false; <br /> } <br /> <br /> return true; <br /> <br /> } <br /> <br /> <br /> <br /> public static void main(String[] args) { <br /> SessionFactory sessionFactory=null; <br /> try { <br /> <br /> sessionFactory=new Configuration().configure().buildSessionFactory(); <br /> UserDao ud=new UserDao(); <br /> UserModel um=new UserModel(); <br /> um.setName("xyb"); <br /> um.setAge(new Integer(10)); <br /> ud.create(um, sessionFactory); <br /> } catch (HibernateException e) { <br /> e.printStackTrace(); <br /> } <br /> <br /> } <br />}<br /><strong>问题补充:</strong><br />mysql我重新启动了,没有问题,用的端口也3306,我安的mysql版本是mysql-5.1.34-win32.msi,我用mysql-gui-tools-5.0-r17-win32.msi我也不知道是不是mysql的版本原因<br /><strong>问题补充:</strong><br />我觉得也是 <br />我想问一下大家:我现在用的驱动是mm.mysql-2.0.4-bin.jar <br />我知道还有一个驱动是mysql-connector-java-3.0.16-ga-bin.jar这两者之间有什么区别,如果我用第二个,那么我的hibernate.cfg.xml真不好意思,麻烦大家这么长时间.<br /><strong>问题补充:</strong><br />各们兄弟,问题找到了,从十点到现在一直在找这个问题,终于找到问题了,我换了一个驱动就行了,以前用mm.mysql-2.0.4-bin.jar ,现在改成了mysql-connector-java-3.0.16-ga-bin.j就能运行,在hibernate.cfg.xml里面改了一下就行了,特别感谢lovewhzlq兄弟.能留下你的qq吗,以后有什么问题请教你。但是为什么用mm.mysql-2.0.4-bin.jar 不行,我也不知道,如果谁知道了,请分享一下.<br /><strong>问题补充:</strong><br />主要是项目中都用那个,我也不是领导,别人这样用,我只能这样用了

Hibernate+Spring整合后自动建表问题

我测试了一个项目,初期没有问题,但是当我修改了自动生成的数据信息后发现,重新部署后数据仍然为原来的信息,接着我尝试了修改表名,重新部署后表名也和原来一样。 以下是配置信息: Hibernate: <session-factory> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="jdbc.batch_size">20</property> <property name="hbm2ddl.auto">${hibernate.auto}</property> <property name="connection.autocommit">true</property> <!-- 显示sql语句 --> <property name="show_sql">true</property> <property name="format_sql">false</property> <property name="connection.useUnicode">true</property> <property name="connection.characterEncoding">UTF-8</property> <!-- 缓存设置 --> <property name="cache.provider_configuration_file_resource_path">classpath:hibernate-ehcache.xml</property> <property name="hibernate.cache.region.factory_class">org.hibernate.cache.SingletonEhCacheRegionFactory</property> <property name="hibernate.cache.use_query_cache">false</property> </session-factory> spring: <!-- 数据库连接池c3p0配置 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="jdbcUrl" value="${db.url}"></property> <property name="properties" ref="dataSourceProperties"/> <property name="driverClass" value="${db.driver}"></property> <property name="maxPoolSize" value="40"></property> <property name="minPoolSize" value="10"></property> <property name="initialPoolSize" value="10"></property> <property name="maxIdleTime" value="60"></property> <property name="idleConnectionTestPeriod" value="360" /> <property name="preferredTestQuery" value="select 1" /> <property name="acquireIncrement" value="5" /> <property name="acquireRetryAttempts" value="50" /> <property name="acquireRetryDelay" value="1000" /> <property name="breakAfterAcquireFailure" value="true" /> <property name="autoCommitOnClose" value="false" /> <property name="testConnectionOnCheckout" value="true" /> <property name="maxStatements" value="100" /> <property name="maxStatementsPerConnection" value="5" /> </bean> <!-- session工厂 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="configLocation" value="classpath:hibernate.cfg.xml"/> <property name="annotatedClasses"> <list> <value>com.gdms.model.rbac.Department</value> <value>com.gdms.model.rbac.Role</value> <value>com.gdms.model.rbac.Permission</value> <value>com.gdms.model.rbac.User</value> </list> </property> <!-- xml自动扫描方式配置的hibernate类文件 --> <property name="mappingLocations"> <value>classpath:com/gdms/model/*.hbm.xml</value> </property> </bean> 我自己做的几次测试 BUG信息:hibernate自动建表信息与配置文件和hbm配置信息不一致。 使用配置文件无法控制hibernate自动建表,而且无法找到hibernate自动建表的表名来源。 测试过程中要十分注意缓存问题 测试1:首先测试数据库连接是否还有用。 测试方法:修改数据库连接信息密码,使密码错误。 测试结果:测试显示配置文件仍然能够使用,并且配置数据库信息 测试2:不使用Hibernate自动建表 测试方法:将hibernate.atuo修改为None 测试结果:即使hibernate.atuo修改为None,仍然进行了自动建表。 目前结论,可以确定目前出现的bug与hibernate.atuo没有关联,因为部队Hibernate.auto设置任何信息,hibernate仍然会完成自动建表。 测试3:查看Init方法是否对建表数据产生影响 测试方法:修改数据 测试结果:修改数据没有用,数据仍然产生为以前数据。 测试4:查看修改信息是否对数据库中数据是否产生影响 测试方法:修改初始化方法的数据 测试结果:没有任务影响 目前结论:可以确定目前的建表与Hibernate没有关系,与项目中的init方法也没有关系,目前推测数据来源:一是存在数据缓存,二是存在某种异常处理手段。

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

删库了,我们一定要跑路吗?

在工作中,我们误删数据或者数据库,我们一定需要跑路吗?我看未必,程序员一定要学会自救,神不知鬼不觉的将数据找回。 在 mysql 数据库中,我们知道 binlog 日志记录了我们对数据库的所有操作,所以 binlog 日志就是我们自救的利器。 接下来就来开启程序员自救之路。 想要自救成功,binlog 这把利器一定要好,在自己之前,我们一定要确定我们有 binlog 这把利器,以下就是确保有 bi...

再不跳槽,应届毕业生拿的都比我多了!

跳槽几乎是每个人职业生涯的一部分,很多HR说“三年两跳”已经是一个跳槽频繁与否的阈值了,可为什么市面上有很多程序员不到一年就跳槽呢?他们不担心影响履历吗? PayScale之前发布的**《员工最短任期公司排行榜》中,两家码农大厂Amazon和Google**,以1年和1.1年的员工任期中位数分列第二、第四名。 PayScale:员工最短任期公司排行榜 意外的是,任期中位数极小的这两家公司,薪资...

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

华为初面+综合面试(Java技术面)附上面试题

华为面试整体流程大致分为笔试,性格测试,面试,综合面试,回学校等结果。笔试来说,华为的难度较中等,选择题难度和网易腾讯差不多。最后的代码题,相比下来就简单很多,一共3道题目,前2题很容易就AC,题目已经记不太清楚,不过难度确实不大。最后一题最后提交的代码过了75%的样例,一直没有发现剩下的25%可能存在什么坑。 笔试部分太久远,我就不怎么回忆了。直接将面试。 面试 如果说腾讯的面试是挥金如土...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

现代的 “Hello, World”,可不仅仅是几行代码而已

作者 |Charles R. Martin译者 | 弯月,责编 | 夕颜头图 |付费下载自视觉中国出品 | CSDN(ID:CSDNnews)新手...

!大部分程序员只会写3年代码

如果世界上都是这种不思进取的软件公司,那别说大部分程序员只会写 3 年代码,恐怕就没有程序员这种职业。

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

HTTP与HTTPS的区别

面试官问HTTP与HTTPS的区别,我这样回答让他竖起大拇指!

程序员毕业去大公司好还是小公司好?

虽然大公司并不是人人都能进,但我仍建议还未毕业的同学,尽力地通过校招向大公司挤,但凡挤进去,你这一生会容易很多。 大公司哪里好?没能进大公司怎么办?答案都在这里了,记得帮我点赞哦。 目录: 技术氛围 内部晋升与跳槽 啥也没学会,公司倒闭了? 不同的人脉圈,注定会有不同的结果 没能去大厂怎么办? 一、技术氛围 纵观整个程序员技术领域,哪个在行业有所名气的大牛,不是在大厂? 而且众所...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

立即提问
相关内容推荐