0
我有一個postgree數據庫。還有spring + hibernate。當我不想通過任何標準獲取實體時,它會返回我的長度列表。看起來像某些依賴被遺漏,或像實體一樣被識別爲實體。無法從數據庫獲取實體
我Maven的配置: ...
<spring.version>4.0.3.RELEASE</spring.version>
<hibernate.version>3.6.9.Final</hibernate.version>
....
<!-- Spring framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<!--Spring and Transactions-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring ORM support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
我的Spring配置
<context:component-scan base-package="com.helper.api,com.helper.db.model"/>
<bean id="eyeDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.user}"/>
<property name="password" value="${db.password}"/>
</bean>
<bean id="hibernate3AnnotatedSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="eyeDataSource" />
<property name="annotatedPackages">
<list>
<value>com.helper.db.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.connection.url">jdbc:postgresql://localhost:5432/xxxxxxxxx_db</prop>
<prop key="hibernate.connection.driver_class">org.postgresql.Driver</prop>
<prop key="hibernate.connection.username">xxxxxxxxx</prop>
<prop key="hibernate.connection.password">qwerty123</prop>
</props>
</property>
</bean>
所以問題是
session.createSQLQuery("SELECT * FROM account").list()
這是返回正確的數據。我在桌上有1條記錄。這是返回 但它是簡單的SQL。當我改變它等於標準
session.createCriteria(AccountEntity.class).list()
它沒有任何回報我什麼。 AccountEntity:
@Entity
@Table(name = "account", schema = "public", catalog = "XXXXXXXX_db")
public class AccountEntity {
private int mId;
private String mName;
private String mPassword;
private Collection<AccountInProductEntity> mAccountInProductsById;
private Collection<ProductEntity> mProductsById;
@Id
@Column(name = "id", nullable = false, insertable = true, updatable = true)
public int getId() {
return mId;
}
public void setId(int id) {
mId = id;
}
@Basic
@Column(name = "name", nullable = false, insertable = true, updatable = true, length = 250)
public String getName() {
return mName;
}
public void setName(String name) {
mName = name;
}
@Basic
@Column(name = "password", nullable = false, insertable = true, updatable = true, length = 50)
public String getPassword() {
return mPassword;
}
public void setPassword(String password) {
mPassword = password;
}
@Override
public boolean equals(Object o) {
....
}
@Override
public int hashCode() {
....
}
@OneToMany(mappedBy = "accountByAccountId")
public Collection<AccountInProductEntity> getAccountInProductsById() {
return mAccountInProductsById;
}
public void setAccountInProductsById(Collection<AccountInProductEntity> accountInProductsById) {
mAccountInProductsById = accountInProductsById;
}
@OneToMany(mappedBy = "accountByOwnerId")
public Collection<ProductEntity> getProductsById() {
return mProductsById;
}
public void setProductsById(Collection<ProductEntity> productsById) {
mProductsById = productsById;
}
}
您可以標記你的答案是正確的,所以可以證明了一個問題,在回答搜索。 – 2014-12-02 10:38:13
是的,會在2天內完成,stackowerflow策略 – 2014-12-02 13:03:38