posted 5 years ago
Hello
I need to retrieve rows from database based on a particular column value.
In this example, there are 4 rows with enrollmentNo as 1110. It runs successfully, but prints the same row data 4 times. (In the table enrollmentNo is the foreign key, does it affects the output? i guess no)
I need to retrieve rows from database based on a particular column value.
In this example, there are 4 rows with enrollmentNo as 1110. It runs successfully, but prints the same row data 4 times. (In the table enrollmentNo is the foreign key, does it affects the output? i guess no)
kunal
Kunal Lakhani
Ranch Hand
Posts: 622
posted 5 years ago
Why you are getting duplicates is impossible to diagnose without knowing your relationships.
You could add
after you are done setting your restrictions. Be aware you will still contain all the duplicates in your result set, this does not reduce the amount of data fetched from the DB or what is sent over the wire. The removing of duplicates is handled on the java side.
Alternatively you can use projections. If you go that route be aware you have to specify all the property's you want fetched.
You could add
after you are done setting your restrictions. Be aware you will still contain all the duplicates in your result set, this does not reduce the amount of data fetched from the DB or what is sent over the wire. The removing of duplicates is handled on the java side.
Alternatively you can use projections. If you go that route be aware you have to specify all the property's you want fetched.
Kunal Lakhani
Ranch Hand
Posts: 622
Kunal Lakhani
Ranch Hand
Posts: 622
posted 5 years ago
The problem is the 4 rows you are getting back are the same entity (they are duplicates). They have the same persistent id whatever that is for your TuitionPaymentEntity. If that were not the case then you would have more than one result. You need to re-examine your relationships and mappings.
Kunal Lakhani
Ranch Hand
Posts: 622
posted 5 years ago
My table Db Structure
The enrollment number used here (and in my code) refers to a primary key of another table(i.e ENROLLMENTNO column of studentpersonal table)
Here is the hbm.xml part for this structure
Is this the problem? Is Foreign key mapped in a different way?
I have not coded for any type of mappings like one-to one or one-to-many.
The enrollment number used here (and in my code) refers to a primary key of another table(i.e ENROLLMENTNO column of studentpersonal table)
Here is the hbm.xml part for this structure
Is this the problem? Is Foreign key mapped in a different way?
I have not coded for any type of mappings like one-to one or one-to-many.
kunal

Not so fast naughty spawn! I want you to know about
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
|