-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate annotations
PostPosted: Thu Sep 02, 2010 7:26 am 
Beginner
Beginner

Joined: Thu Jun 24, 2010 2:30 am
Posts: 23
Hi,

I created a table in MySQL:

'object_label' with columns 'id' and 'name'.
I inserted values to this table.

In java I created new class -'ObjectLabel':

Code:
   @Entity
    @Table(name = "object_label")
    public class ObjectLabel  implements Serializable {
   
       private static final long serialVersionUID = 3475812350796110403L;
       private String name;
       
        public Long getId() { return id; }

        @Id   
        @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(precision = 10, unique = true, nullable = false, updatable = false)
   public Long getId() {
      return id;
   }

   public void setId( Long id ) {
      this.id = id;
   }
   
       /**
        * @return the name
        */
       public String getName() {
          return name;
       }
       /**
        * @param name the name to set
        */
       public void setName(String name) {
          this.name = name;
       }
       
   
    }

in hibernate.cfg.xml defined:

Code:
<mapping class="com.myCompany.model.ObjectLabel" />


I whant to get the valuse from the table,
I definded service :

Code:
@SuppressWarnings( "unchecked" )
   @Transactional( readOnly = true, propagation = Propagation.SUPPORTS )
   public Collection<T> findAll() {
      Session session = getSessionFactory().getCurrentSession();
      
      return
         session.createCriteria( persistentClass
               ).setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY
                     ).list();
   }


I gets empty list.

in the database
Code:
select * from 'object_label'
return the values)

what the problem in my code?

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.