【发布时间】:2011-03-28 22:59:06
【问题描述】:
我在 Hibernate 看到我的域对象为 Hibernate 进行纯粹的注释配置时遇到问题。
我来了
org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User u where u.userName=:userName]
我认为只需为 sessionFactory 添加packagesToScan 属性并将@Entity 添加到域对象即可。我还缺少什么?
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.trx.sample.domain" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
</props>
</property>
<property name="eventListeners">
<map>
<entry key="merge">
<bean
class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" />
</entry>
</map>
</property>
</bean>
<context:annotation-config />
<tx:annotation-driven />
-
package com.trx.sample.domain;
@Entity
@Table(name = "user")
public class User extends BaseEntity implements UserDetails {
private static final long serialVersionUID = 1L;
@Column(name = "user_name")
private String userName;
private String password;
private boolean enabled;
private String roles;
...
}
-
@MappedSuperclass
public class BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long id;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public boolean isNew() {
return (this.id == null);
}
}
-
[INFO] building session factory
[DEBUG] Session factory constructed with filter configurations : {}
[DEBUG] instantiating session factory with properties: {...}
[DEBUG] initializing class SessionFactoryObjectFactory
[DEBUG] registered: 402881e52a6b3159012a6b3163e40000 (unnamed)
[INFO] Not binding factory to JNDI, no JNDI name configured
[DEBUG] instantiated session factory
[DEBUG] Checking 0 named HQL queries
[DEBUG] Checking 0 named SQL queries
编辑:
不知道它是否有区别,但我正在通过 eclipse 在 tomcat 实例上运行它。
【问题讨论】:
-
Hibernate 在启动时非常冗长,它应该在映射时提及每个类。它说什么?
-
它并不表示它正在映射任何东西。
标签: hibernate spring orm configuration annotations