You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "aabbcc (Created) (JIRA)" <ji...@apache.org> on 2012/02/22 10:38:48 UTC
[jira] [Created] (OPENJPA-2138) One-To-Many mapping is not working
One-To-Many mapping is not working
----------------------------------
Key: OPENJPA-2138
URL: https://issues.apache.org/jira/browse/OPENJPA-2138
Project: OpenJPA
Issue Type: Bug
Components: jpa
Affects Versions: 2.1.1
Reporter: aabbcc
I have business object model with below structure
Class A {
private B b;
}
Class B {
private String joinKey;
private List<C> c;
}
Class C {
private String joinKey;
private String str1;
private String str2;
}
In the ORM.xml,I have specified mapping like this
<entity class="xxx.xxx.A">
<table name="table1"/>
<attributes>
<one-to-one name="name1" target-entity="xxx.xxx.B">
<join-column name='"column1"' referenced-column-name='"column1"'/>
</one-to-one>
</attributes>
</entity>
<entity class="xxx.xxx.B">
<table name="table2"/>
<attributes>
<basic name="joinKey">
<column name="column1"/>
</basic>
<one-to-many name="name1" target-entity="xxx.xxx.C">
<join-column name='"column1"' referenced-column-name='"column1"'/>
</one-to-many>
</attributes>
</entity>
<entity class="xxx.xxx.C">
<attributes>
<basic name="joinKey">
<column name="column1"/>
</basic>
<basic name="str1">
<column name="str1Column"/>
</basic>
<basic name="str2">
<column name="str2Column"/>
</basic>
</attributes>
</entity>
The one-to-many mapping specified in the entity C does not work by both approach 1) JoinColumn 2) JoinTable. My code skips this mapping while generating SQL query.
But instead of one-to-many mapping If I specify one-to-one mapping and change class B to replace "private List<C> c;" with "private C c;" then the one-to-one mapping works fine.
I am using OPENJpa 2.1.1, as per the documentation one-to-many mapping should work but it seems OPENJpa 2.1.1 API is working as expected. It seems there is bug in API.
Can you please advise to fix this issue?
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
Re: [jira] [Created] (OPENJPA-2138) One-To-Many mapping is not working
Posted by Kevin Sutter <kw...@gmail.com>.
Hi,
By default, collection-based relationships (ie. one-to-many) are lazily
fetched. That means that they will not be included in a query of the
entity containing this relationship. You either need to touch that
collection filed or change the fetch mode to Eager.
Kevin
On Wed, Feb 22, 2012 at 3:38 AM, aabbcc (Created) (JIRA) <ji...@apache.org>wrote:
> One-To-Many mapping is not working
> ----------------------------------
>
> Key: OPENJPA-2138
> URL: https://issues.apache.org/jira/browse/OPENJPA-2138
> Project: OpenJPA
> Issue Type: Bug
> Components: jpa
> Affects Versions: 2.1.1
> Reporter: aabbcc
>
>
> I have business object model with below structure
>
> Class A {
> private B b;
>
> }
>
> Class B {
> private String joinKey;
> private List<C> c;
> }
>
> Class C {
> private String joinKey;
> private String str1;
> private String str2;
> }
>
> In the ORM.xml,I have specified mapping like this
>
> <entity class="xxx.xxx.A">
> <table name="table1"/>
> <attributes>
> <one-to-one name="name1" target-entity="xxx.xxx.B">
> <join-column name='"column1"' referenced-column-name='"column1"'/>
> </one-to-one>
> </attributes>
> </entity>
>
> <entity class="xxx.xxx.B">
> <table name="table2"/>
> <attributes>
> <basic name="joinKey">
> <column name="column1"/>
> </basic>
> <one-to-many name="name1" target-entity="xxx.xxx.C">
> <join-column name='"column1"' referenced-column-name='"column1"'/>
> </one-to-many>
> </attributes>
> </entity>
>
> <entity class="xxx.xxx.C">
> <attributes>
> <basic name="joinKey">
> <column name="column1"/>
> </basic>
> <basic name="str1">
> <column name="str1Column"/>
> </basic>
> <basic name="str2">
> <column name="str2Column"/>
> </basic>
> </attributes>
>
> </entity>
>
>
> The one-to-many mapping specified in the entity C does not work by both
> approach 1) JoinColumn 2) JoinTable. My code skips this mapping while
> generating SQL query.
> But instead of one-to-many mapping If I specify one-to-one mapping and
> change class B to replace "private List<C> c;" with "private C c;" then the
> one-to-one mapping works fine.
>
> I am using OPENJpa 2.1.1, as per the documentation one-to-many mapping
> should work but it seems OPENJpa 2.1.1 API is working as expected. It seems
> there is bug in API.
>
> Can you please advise to fix this issue?
>
> --
> This message is automatically generated by JIRA.
> If you think it was sent incorrectly, please contact your JIRA
> administrators:
> https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
> For more information on JIRA, see: http://www.atlassian.com/software/jira
>
>
>
[jira] [Closed] (OPENJPA-2138) One-To-Many mapping is not working
Posted by "aabbcc (Closed) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-2138?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
aabbcc closed OPENJPA-2138.
---------------------------
Resolution: Cannot Reproduce
> One-To-Many mapping is not working
> ----------------------------------
>
> Key: OPENJPA-2138
> URL: https://issues.apache.org/jira/browse/OPENJPA-2138
> Project: OpenJPA
> Issue Type: Bug
> Components: jpa
> Affects Versions: 2.1.1
> Reporter: aabbcc
>
> I have business object model with below structure
> Class A {
> private B b;
> }
> Class B {
> private String joinKey;
> private List<C> c;
> }
> Class C {
> private String joinKey;
> private String str1;
> private String str2;
> }
> In the ORM.xml,I have specified mapping like this
> <entity class="xxx.xxx.A">
> <table name="table1"/>
> <attributes>
> <one-to-one name="name1" target-entity="xxx.xxx.B">
> <join-column name='"column1"' referenced-column-name='"column1"'/>
> </one-to-one>
> </attributes>
> </entity>
> <entity class="xxx.xxx.B">
> <table name="table2"/>
> <attributes>
> <basic name="joinKey">
> <column name="column1"/>
> </basic>
> <one-to-many name="name1" target-entity="xxx.xxx.C">
> <join-column name='"column1"' referenced-column-name='"column1"'/>
> </one-to-many>
> </attributes>
> </entity>
> <entity class="xxx.xxx.C">
> <attributes>
> <basic name="joinKey">
> <column name="column1"/>
> </basic>
> <basic name="str1">
> <column name="str1Column"/>
> </basic>
> <basic name="str2">
> <column name="str2Column"/>
> </basic>
> </attributes>
> </entity>
> The one-to-many mapping specified in the entity C does not work by both approach 1) JoinColumn 2) JoinTable. My code skips this mapping while generating SQL query.
> But instead of one-to-many mapping If I specify one-to-one mapping and change class B to replace "private List<C> c;" with "private C c;" then the one-to-one mapping works fine.
> I am using OPENJpa 2.1.1, as per the documentation one-to-many mapping should work but it seems OPENJpa 2.1.1 API is working as expected. It seems there is bug in API.
> Can you please advise to fix this issue?
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira