hibernate - Can't get an Entity from db -


i have postgree db. , spring+hibernate. when wan't entity criteria, return me 0 length list. looks dependency missed, or entity isn't recognized entity.

my maven config: ...

   <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 , 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> 

my spring config

<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> 

so problem is

session.createsqlquery("select * account").list() 

this returns correct data. have 1 record in table. returned simple sql. when change equal criteria

session.createcriteria(accountentity.class).list() 

it has no return me anything. 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;     } } 

my mistake in spring config used

   <property name="annotatedpackages">        <list>           <value>com.tac.helper.db.model</value>         </list>    </property> 

instead

    <property name="packagestoscan">         <list>             <value>com.tac.helper.db.model</value>         </list>     </property> 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -