spring3.2+hibernate4 注解配置报错:No identifier specified for entity

lihbsd 2014-03-07 11:29:22
spring3.2+hibernate4 注解配置报错:No identifier specified for entity: com.jialin.entity.SysDefinitionField。
BAIDU,GOOGLE一天了,也没有解决。求救啊!

entity类如下:

package com.jialin.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "sys_definition_table")
public class SysDefinitionTable {
private int id;
private String name;
private String dbname;

@Column(name="name", length=30, nullable=false, unique=true)
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Column(name="dbname", length=20, nullable=false, unique=true)
public String getDbname() {
return dbname;
}

public void setDbname(String dbname) {
this.dbname = dbname;
}


@Id
@Column(name="id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}
}


spring配置如下:applicationContext-common.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

<!-- 启用spring注解支持 -->
<context:annotation-config />

<!--配数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://127.0.0.1:3306/SSH2TEST" />
<property name="username" value="root" />
<property name="password" value="524433161" />
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="default_schema">ssh2test</prop>

</props>
</property>
<!-- 指定实体类包 -->
<property name="packagesToScan" value="com.jialin.entity*">

</property>
</bean>


<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 事务的传播特性 -->
<tx:advice id="txadvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />

<!--hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到-->
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>

<!-- 那些类那些方法使用事务 -->
<aop:config>
<!-- 只对业务逻辑层实施事务 -->
<aop:pointcut id="allManagerMethod"
expression="execution(* com.jialin.service.*.*(..))" />
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txadvice" />
</aop:config>


</beans>




hibernate配置如下:hibernate.cfg.xml

<?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>
<!-- 为true表示将Hibernate发送给数据库的sql显示出来 -->
<property name="show_sql">true</property>
<!-- SQL方言,这边设定的是MySQL -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/SSH2TEST</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">524433161</property> -->
<!--数据库连接池的大小-->
<!-- <property name="hibernate.connection.pool.size">20</property> -->

<mapping class="com.jialin.entity.User"/>
<mapping class="com.jialin.entity.SysDefinitionTable"/>
</session-factory>

</hibernate-configuration>


是在一个代码例子上模仿添加的SysDefinitionTable,删除添加的内容,User的配置的有效的。

到底是哪里搞错了呢,求解!在线等啊!
...全文
7617 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lihbsd 2014-03-07
  • 打赏
  • 举报
回复
引用 1 楼 zhouren1314 的回复:
报错是这个实体类:No identifier specified for entity: com.jialin.entity.SysDefinitionField。 你贴的代码实体类名称不对啊
我晕死了,entiry包里多了一个没有完成的实体类。 做事粗心害死人啊!!!!
乔不思 2014-03-07
  • 打赏
  • 举报
回复
报错是这个实体类:No identifier specified for entity: com.jialin.entity.SysDefinitionField。 你贴的代码实体类名称不对啊
Defonds 2014-03-07
  • 打赏
  • 举报
回复
1. id 是那个表的主键吗?还是有其他主键? 2. hibernate 关于实体类的配置没贴出来呢

81,092

社区成员

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

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