-->
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.  [ 8 posts ] 
Author Message
 Post subject: How to retrieve records from a table
PostPosted: Mon Nov 14, 2016 2:50 am 
Newbie

Joined: Mon Nov 14, 2016 2:35 am
Posts: 4
Hello,

I have a question regarding how to retrieve records from a table that consists with one composite key.
In my hbm.cfg I have specified my composite key with this section:

<composite-id>
<key-property name="year"/>
<key-property name="month"/>
</composite-id>

I have a POJO class with all the "columns" that exists in my table.
How should I write this POJO class regarding to my composite key.

In the same package I hava a DAO class that retreives all records from the database.
How should I write a DAO method that retrieves all records from the table regarding to my composite key.
SQL query: select year,month,sallary from sallary where year>=2002

If I don't specify the composite key in my hbm.cfg hibernate retrieves too many records in my DAO object.
One record will be listed several times in the query result. Don't know why!


Top
 Profile  
 
 Post subject: Re: How to retrieve records from a table
PostPosted: Mon Nov 14, 2016 6:14 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I wonder how is it possible to have a UNIQUE identifier that's based on YEAR and MONTH, while you store salaries.

Is this really the Primary Key on that table?


Top
 Profile  
 
 Post subject: Re: How to retrieve records from a table
PostPosted: Mon Nov 14, 2016 7:49 am 
Newbie

Joined: Mon Nov 14, 2016 2:35 am
Posts: 4
It is an example of my problem. This is not the real program.


Top
 Profile  
 
 Post subject: Re: How to retrieve records from a table
PostPosted: Mon Nov 14, 2016 7:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Unless you provide the actual problem and a lot of info about what you are trying to do, there is little chance that you'll get the right answer.


Top
 Profile  
 
 Post subject: Re: How to retrieve records from a table
PostPosted: Mon Nov 14, 2016 8:00 am 
Newbie

Joined: Mon Nov 14, 2016 2:35 am
Posts: 4
Hmm, so is it impossible to describe for me the priniciples on how to retrieve records from a table with a composite key?


Top
 Profile  
 
 Post subject: Re: How to retrieve records from a table
PostPosted: Mon Nov 14, 2016 9:43 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Have you checked our User Guide?


Top
 Profile  
 
 Post subject: Re: How to retrieve records from a table
PostPosted: Mon Nov 14, 2016 9:58 am 
Newbie

Joined: Mon Nov 14, 2016 2:35 am
Posts: 4
Can I use this guide for Hibernate 3.2?


Top
 Profile  
 
 Post subject: Re: How to retrieve records from a table
PostPosted: Mon Nov 14, 2016 10:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
This guide is written for Hibernate 5. We no longer maintain Hibernate 3 or 4. You can check the old documentation, but it's not as neat as the Hibernate 5 one, which was rewritten from scratch.

While I can surely help you if you are using annotations, I haven't used any legacy XML mapping for the past 8 years, so I don't remember the quirks associated with those mappings. Anyway, the legacy HBM mapping is going to be deprecated in a future version of Hibernate, so you are going to find less and less resources for such an old version of Hibernate.


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

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.