| Author |
No row with the given identifier exists:
|
Zaw Aung
Greenhorn
Joined: Jun 18, 2008
Posts: 9
|
|
I would like to avoid "No row with the given identifier exists:" exception.
I have two tables . MainTransaction and SubTransaction
MainTransaction Table has four fields
1.Transaction ID (Primary Key)
2.BranchID
3.BranchName
4.BranchAddress
BranchID and BranchName are foreinkey to link to SubTransaction Table..
SubTransaction Table has five fields
1.BranchID
2.BranchName
3.Location
4.Activity
BranchID and BranchName are composite id to link to MainTransaction Table.
Here are the Java Class Declarations....
__________________________________________________________________________________--
____________________________________________________________________________________________________
Here is relationship in the mapping file (MainTransaction.hbm.xml).. Mapping is okay. The problem is that I get the exception(No row with the given identifier exists
When I execute the "mainTransaction.getSubTran" getter method with no related record in subTransaction table. I do not want the exeception. I just want to check whether null or not and want to continue the program execution..
Here is codes that raise the exception
Please tell me if you have any idea......
With Regards......
|
 |
Balagopal Kannampallil
Ranch Hand
Joined: Oct 18, 2004
Posts: 111
|
|
Hi,
Please wrap your code inside the [code] tag to make it more readable so that we can save our time and help you better.
|
Bala
SCJP 5.0
Gonna hunt down SCWCD soon..
|
 |
Zaw Aung
Greenhorn
Joined: Jun 18, 2008
Posts: 9
|
|
Ok..
|
 |
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2549
|
|
|
"Raining Sky " please see your private messages for an important administrative matter.
|
SCJP, SCWCD.
|Asking Good Questions|
|
 |
Javid Jamae
Author
Ranch Hand
Joined: May 14, 2008
Posts: 198
|
|
|
Can you show us the mapping for SubTransaction?
|
Author: JBoss in Action, javidjamae.com, @javidjamae on Twitter
|
 |
Zaw Aung
Greenhorn
Joined: Jun 18, 2008
Posts: 9
|
|
Here is the mapping file for SubTransaction Table.. Just mapping to Table.. I want only unidirectional mapping.
|
 |
Javid Jamae
Author
Ranch Hand
Joined: May 14, 2008
Posts: 198
|
|
Can you show us the data in the two DB tables. Do all the FK's match up consistently between the tables?
Also, can you show me the entire error message. In particular, what comes after the colon?
|
 |
Zaw Aung
Greenhorn
Joined: Jun 18, 2008
Posts: 9
|
|
Here is the error messages.. I know that there is no related record in SubTransaction table.. But I want to return null. I do not want to throw the exception.
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [SubTransaction#SubTransactionPK@aa233f]
at org.hibernate.impl.SessionFactoryImpl$1.handleEntityNotFound(SessionFactoryImpl.java:377)
at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:79)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:68)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
Note : There is no physical relationship between two tables.
|
 |
Javid Jamae
Author
Ranch Hand
Joined: May 14, 2008
Posts: 198
|
|
|
When you define the <many-to-one> and point the <column> attributes to another table, you are defining a FK relationship. If that foreign key doesn't exist, then you can't have the values populated in the MainTransaction object. If they have no physical relationship, then don't map a Hibernate relationship between the two. You'll just have to load the data you need and manage the object relationship yourself.
|
 |
Zaw Aung
Greenhorn
Joined: Jun 18, 2008
Posts: 9
|
|
Thanks a lot....
What you mean is that if there is physical relationship, the exeception can't throw even. Is it?
|
 |
 |
|
|
subject: No row with the given identifier exists:
|
|
|