Home » Modeling » EMF » [Teneo] Use of constrained=true for 1 to 1?
|
Re: [Teneo] Use of constrained=true for 1 to 1? [message #427106 is a reply to message #427101] |
Mon, 02 February 2009 13:02 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi David,
Constrained=true is only added if the association is required/mandatory. See here: http://www.hibernate.org/162.html and
then specifically this remark on that page:
So the resume: if your B->C mapping is mandatory (constrainted=true), Hibernate will use proxy for C resulting in lazy
initialization. But if you allow B without C, Hibernate just HAS TO check presence of C at the moment it loads B. But a
SELECT to check presence is just inefficient because the same SELECT may not just check presence, but load entire
object. So lazy loading goes away.
So I am wondering what would be a good other solution to solve this...
Do you have control over the db schema, can you choose where to place the foreign key columns?
gr. Martin
David Wynter wrote:
> Hi Martin,
>
> I use USE_PROXY ="true" and it marks all my one to one associations with
> lazy="true". But because it does not also add constrained="true" to the
> hbm.xml files these are always eagerly loaded. Is there a reason you do
> not use constrained = "true"
>
> Also I have several one-to-one using PrimaryKeyJoinColumn, like so
>
> <xsd:element ecore:opposite="debtIssueData" minOccurs="0"
> maxOccurs="1" ref="gensec:instrumentDomain">
> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@PrimaryKeyJoinColumn</xsd:appinfo>
> <xsd:appinfo source="teneo.hibernate">@Fetch(JOIN)</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
>
> These should be optional and therefore I would like them to have
> lazy="true" and constrained="true" as well. But they are lazy="false"
>
> <class name="com.stpenable.gensec.impl.DebtIssueDataImpl"
> entity-name="DebtIssueData" abstract="false" lazy="false"
> table="`debtissuedata`">
> <meta attribute="eclassName">DebtIssueData</meta>
> <meta attribute="epackage">http://www.stpenable.com/gensec</meta>
> <id name="id" type="int" unsaved-value="-1">
> <column not-null="true" unique="false" name="`id`"/>
> <generator class="foreign">
> <param name="property">instrumentDomain</param>
> </generator>
> </id>
> ....
>
> How to I get it to make this lazy="true" constrained="true"?
>
> I need to absolutely control the loading of all entities using left join
> fetch and inner join fetch in HQL, so want everything to be lazy loaded.
> Otherwise Hibernate is completely unusable due to poor performance with
> the 5*n+1 selects for every 'n' of the main entities it retrieves in a
> search, which has 5 1to1 associations.
>
> Thx.
>
> David
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
Re: [Teneo] Use of constrained=true for 1 to 1? [message #427108 is a reply to message #427106] |
Mon, 02 February 2009 14:50 |
David Wynter Messages: 4624 Registered: July 2009 |
Senior Member |
|
|
Hi Martin,
I could change the schema, but at this stage it is loaded with customer
data and a hassle.
I do not understand why if the association is optional they HAVE to
check for the null in the optional end. If it is lazy loading surely you
only check that the existence of 'C' in the example below when you have
to lazy load it.
Would JPOX suffer from this behaviour? Its user controlled fetch groups
looks ideal in terms of controlling what is lazily loaded and what is not.
I also tried getSQLQuery to control absolutely what it fetches, like so:
String queryString = "SELECT
{inst.*},{ic.*},{de.*},{c1.*},{inid.*},{si.*},{issid.*},{di. *},{itype.*}
FROM instrumentdomain inst INNER JOIN issuerclass ic ON inst.issuerclass
= ic.id " +
"LEFT OUTER JOIN denomination de ON inst.id = de.instrumentdomain LEFT
OUTER JOIN currency c1 ON ci.id = de.currency " +
"LEFT OUTER JOIN instrumentidentifier inid ON inid.instrumentdomain =
inst.id LEFT OUTER JOIN schemeinfo si ON si.id = inid.schemeinfo " +
"LEFT OUTER JOIN issuedata issid ON issid.id = inst.id LEFT OUTER JOIN
debtissuedata di ON di.id = inst.id " +
"LEFT OUTER JOIN instrumenttype itype ON inst.instrumenttype = itype.id";
// where clause
String separator = " where ";
if (industryIdentifierId != null)
{
queryString += separator + "industry.id = ?";
separator = " and ";
}
if (currencyId != null)
{
queryString += separator + "c1.id = ?";
separator = " and ";
}
if (countryId != null)
{
queryString += separator + "cntry.id = ?";
separator = " and ";
}
if(instrumentTypeId==null) {
queryString += separator + "itype.id in
(46,48,49,150,151,185,432,438,439,443,473)";
separator = " and ";
} else {
queryString += separator + "itype.id = ?";
separator = " and ";
}
if (name != null)
{
if (name.indexOf('%') >= 0)
queryString += separator + "inst.name like ?";
else
queryString += separator + "inst.name = ?";
separator = " and ";
}
if (lastCaeDtFrom != null || lastCaeDtTo != null)
{
queryString += separator;
if (lastCaeDtFrom != null)
queryString += " inst.lastCAE >= ?" + (lastCaeDtTo == null ? "" : " and");
if (lastCaeDtTo != null)
queryString += " inst.lastCAE <= ?";
}
SQLQuery sqlquery =
session.createSQLQuery(queryString).addEntity("inst",
InstrumentDomainImpl.class)
..addEntity("ic", IssuerClassImpl.class)
..addEntity("de",DenominationImpl.class)
..addEntity("c1",CurrencyImpl.class)
..addEntity("inid",InstrumentIdentifierImpl.class)
..addEntity("si",SchemeInfoImpl.class)
..addEntity("issid",IssueDataImpl.class)
..addEntity("di",DebtIssueDataImpl.class)
..addEntity("itype",InstrumentTypeImpl.class);
sqlquery.setCacheable(true);
sqlquery.setReadOnly(true);
int arg = 0;
// joins
if (instrumentTypeId != null)
sqlquery.setInteger(arg++, instrumentTypeId);
if (industryIdentifierId != null)
sqlquery.setInteger(arg++, industryIdentifierId);
if (currencyId != null)
sqlquery.setInteger(arg++, currencyId);
if (countryId != null)
sqlquery.setInteger(arg++, countryId);
// where clause
if (name != null)
sqlquery.setString(arg++, name);
if (lastCaeDtFrom != null)
sqlquery.setDate(arg++, lastCaeDtFrom);
if (lastCaeDtTo != null)
sqlquery.setDate(arg++, lastCaeDtTo);
//System.out.println("equity query: " + queryString);
// then create EquityResultRows with the constituent objects
try {
List<InstrumentDomain> results = sqlquery.list();
but it throws with
org.hibernate.MappingException: Unknown entity:
com.stpenable.gensec.impl.InstrumentDomainImpl
If I use the Interfaces instead then I get
org.hibernate.MappingException: Unknown entity:
com.stpenable.gensec.impl.InstrumentDomain
Do I need to addEntity() with some ECore class instead?
Thx.
David
Martin Taal wrote:
> Hi David,
> Constrained=true is only added if the association is required/mandatory.
> See here: http://www.hibernate.org/162.html and then specifically this
> remark on that page:
>
> So the resume: if your B->C mapping is mandatory (constrainted=true),
> Hibernate will use proxy for C resulting in lazy initialization. But if
> you allow B without C, Hibernate just HAS TO check presence of C at the
> moment it loads B. But a SELECT to check presence is just inefficient
> because the same SELECT may not just check presence, but load entire
> object. So lazy loading goes away.
>
> So I am wondering what would be a good other solution to solve this...
>
> Do you have control over the db schema, can you choose where to place
> the foreign key columns?
>
> gr. Martin
>
> David Wynter wrote:
>> Hi Martin,
>>
>> I use USE_PROXY ="true" and it marks all my one to one associations
>> with lazy="true". But because it does not also add constrained="true"
>> to the hbm.xml files these are always eagerly loaded. Is there a
>> reason you do not use constrained = "true"
>>
>> Also I have several one-to-one using PrimaryKeyJoinColumn, like so
>>
>> <xsd:element ecore:opposite="debtIssueData" minOccurs="0"
>> maxOccurs="1" ref="gensec:instrumentDomain">
>> <xsd:annotation>
>> <xsd:appinfo
>> source="teneo.jpa">@PrimaryKeyJoinColumn</xsd:appinfo>
>> <xsd:appinfo
>> source="teneo.hibernate">@Fetch(JOIN)</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>>
>> These should be optional and therefore I would like them to have
>> lazy="true" and constrained="true" as well. But they are lazy="false"
>>
>> <class name="com.stpenable.gensec.impl.DebtIssueDataImpl"
>> entity-name="DebtIssueData" abstract="false" lazy="false"
>> table="`debtissuedata`">
>> <meta attribute="eclassName">DebtIssueData</meta>
>> <meta attribute="epackage">http://www.stpenable.com/gensec</meta>
>> <id name="id" type="int" unsaved-value="-1">
>> <column not-null="true" unique="false" name="`id`"/>
>> <generator class="foreign">
>> <param name="property">instrumentDomain</param>
>> </generator>
>> </id>
>> ....
>>
>> How to I get it to make this lazy="true" constrained="true"?
>>
>> I need to absolutely control the loading of all entities using left
>> join fetch and inner join fetch in HQL, so want everything to be lazy
>> loaded. Otherwise Hibernate is completely unusable due to poor
>> performance with the 5*n+1 selects for every 'n' of the main entities
>> it retrieves in a search, which has 5 1to1 associations.
>>
>> Thx.
>>
>> David
>
>
|
|
|
Re: [Teneo] Use of constrained=true for 1 to 1? [message #427109 is a reply to message #427108] |
Mon, 02 February 2009 14:57 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi David,
If the association is optional then hibernate does not know if it should put a proxy object in the member (modeling the
association) or not, at least not without checking. If it is null then hibernate should not put a proxy object in the
member, if it is not null then it should do that. For example assume a o2o between A and B and the foreign key column is
in B pointing to A (B.a), on java level there is a pointer both sides (A.b <--> B.a), A.b is optional, when reading A
how does hibernate know if A.b is set? It can only do this by querying B.a (as the A table does not hold enough info).
So in this case when loading a list of A's, hibernate always has to do extra queries to check for each A.b if it is set
or not. This exta query loads B (eagerly).
For the query approach:
You should use the eclass name instead of the java class in the addEntity method (most/all of these entity methods have
both a class and an entity name variant).
Jpox would not be a better choice right now.
gr. Martin
David Wynter wrote:
> Hi Martin,
>
> I could change the schema, but at this stage it is loaded with customer
> data and a hassle.
>
> I do not understand why if the association is optional they HAVE to
> check for the null in the optional end. If it is lazy loading surely you
> only check that the existence of 'C' in the example below when you have
> to lazy load it.
>
> Would JPOX suffer from this behaviour? Its user controlled fetch groups
> looks ideal in terms of controlling what is lazily loaded and what is not.
>
> I also tried getSQLQuery to control absolutely what it fetches, like so:
>
> String queryString = "SELECT
> {inst.*},{ic.*},{de.*},{c1.*},{inid.*},{si.*},{issid.*},{di. *},{itype.*}
> FROM instrumentdomain inst INNER JOIN issuerclass ic ON inst.issuerclass
> = ic.id " +
> "LEFT OUTER JOIN denomination de ON inst.id = de.instrumentdomain LEFT
> OUTER JOIN currency c1 ON ci.id = de.currency " +
> "LEFT OUTER JOIN instrumentidentifier inid ON inid.instrumentdomain =
> inst.id LEFT OUTER JOIN schemeinfo si ON si.id = inid.schemeinfo " +
> "LEFT OUTER JOIN issuedata issid ON issid.id = inst.id LEFT OUTER JOIN
> debtissuedata di ON di.id = inst.id " +
> "LEFT OUTER JOIN instrumenttype itype ON inst.instrumenttype = itype.id";
>
> // where clause
> String separator = " where ";
> if (industryIdentifierId != null)
> {
> queryString += separator + "industry.id = ?";
> separator = " and ";
> }
> if (currencyId != null)
> {
> queryString += separator + "c1.id = ?";
> separator = " and ";
> }
> if (countryId != null)
> {
> queryString += separator + "cntry.id = ?";
> separator = " and ";
> }
> if(instrumentTypeId==null) {
> queryString += separator + "itype.id in
> (46,48,49,150,151,185,432,438,439,443,473)";
> separator = " and ";
> } else {
> queryString += separator + "itype.id = ?";
> separator = " and ";
> }
>
> if (name != null)
> {
> if (name.indexOf('%') >= 0)
> queryString += separator + "inst.name like ?";
> else
> queryString += separator + "inst.name = ?";
> separator = " and ";
> }
> if (lastCaeDtFrom != null || lastCaeDtTo != null)
> {
> queryString += separator;
> if (lastCaeDtFrom != null)
> queryString += " inst.lastCAE >= ?" + (lastCaeDtTo == null ? ""
> : " and");
> if (lastCaeDtTo != null)
> queryString += " inst.lastCAE <= ?";
> }
>
> SQLQuery sqlquery =
> session.createSQLQuery(queryString).addEntity("inst",
> InstrumentDomainImpl.class)
> ..addEntity("ic", IssuerClassImpl.class)
> ..addEntity("de",DenominationImpl.class)
> ..addEntity("c1",CurrencyImpl.class)
> ..addEntity("inid",InstrumentIdentifierImpl.class)
> ..addEntity("si",SchemeInfoImpl.class)
> ..addEntity("issid",IssueDataImpl.class)
> ..addEntity("di",DebtIssueDataImpl.class)
> ..addEntity("itype",InstrumentTypeImpl.class);
> sqlquery.setCacheable(true);
> sqlquery.setReadOnly(true);
>
> int arg = 0;
>
> // joins
> if (instrumentTypeId != null)
> sqlquery.setInteger(arg++, instrumentTypeId);
> if (industryIdentifierId != null)
> sqlquery.setInteger(arg++, industryIdentifierId);
> if (currencyId != null)
> sqlquery.setInteger(arg++, currencyId);
> if (countryId != null)
> sqlquery.setInteger(arg++, countryId);
>
> // where clause
> if (name != null)
> sqlquery.setString(arg++, name);
> if (lastCaeDtFrom != null)
> sqlquery.setDate(arg++, lastCaeDtFrom);
> if (lastCaeDtTo != null)
> sqlquery.setDate(arg++, lastCaeDtTo);
>
> //System.out.println("equity query: " + queryString);
>
> // then create EquityResultRows with the constituent objects
> try {
> List<InstrumentDomain> results = sqlquery.list();
>
> but it throws with
> org.hibernate.MappingException: Unknown entity:
> com.stpenable.gensec.impl.InstrumentDomainImpl
>
> If I use the Interfaces instead then I get
> org.hibernate.MappingException: Unknown entity:
> com.stpenable.gensec.impl.InstrumentDomain
>
> Do I need to addEntity() with some ECore class instead?
>
> Thx.
>
> David
>
>
> Martin Taal wrote:
>> Hi David,
>> Constrained=true is only added if the association is
>> required/mandatory. See here: http://www.hibernate.org/162.html and
>> then specifically this remark on that page:
>>
>> So the resume: if your B->C mapping is mandatory (constrainted=true),
>> Hibernate will use proxy for C resulting in lazy initialization. But
>> if you allow B without C, Hibernate just HAS TO check presence of C at
>> the moment it loads B. But a SELECT to check presence is just
>> inefficient because the same SELECT may not just check presence, but
>> load entire object. So lazy loading goes away.
>>
>> So I am wondering what would be a good other solution to solve this...
>>
>> Do you have control over the db schema, can you choose where to place
>> the foreign key columns?
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi Martin,
>>>
>>> I use USE_PROXY ="true" and it marks all my one to one associations
>>> with lazy="true". But because it does not also add
>>> constrained="true" to the hbm.xml files these are always eagerly
>>> loaded. Is there a reason you do not use constrained = "true"
>>>
>>> Also I have several one-to-one using PrimaryKeyJoinColumn, like so
>>>
>>> <xsd:element ecore:opposite="debtIssueData" minOccurs="0"
>>> maxOccurs="1" ref="gensec:instrumentDomain">
>>> <xsd:annotation>
>>> <xsd:appinfo
>>> source="teneo.jpa">@PrimaryKeyJoinColumn</xsd:appinfo>
>>> <xsd:appinfo
>>> source="teneo.hibernate">@Fetch(JOIN)</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>>
>>> These should be optional and therefore I would like them to have
>>> lazy="true" and constrained="true" as well. But they are lazy="false"
>>>
>>> <class name="com.stpenable.gensec.impl.DebtIssueDataImpl"
>>> entity-name="DebtIssueData" abstract="false" lazy="false"
>>> table="`debtissuedata`">
>>> <meta attribute="eclassName">DebtIssueData</meta>
>>> <meta
>>> attribute="epackage">http://www.stpenable.com/gensec</meta>
>>> <id name="id" type="int" unsaved-value="-1">
>>> <column not-null="true" unique="false" name="`id`"/>
>>> <generator class="foreign">
>>> <param name="property">instrumentDomain</param>
>>> </generator>
>>> </id>
>>> ....
>>>
>>> How to I get it to make this lazy="true" constrained="true"?
>>>
>>> I need to absolutely control the loading of all entities using left
>>> join fetch and inner join fetch in HQL, so want everything to be lazy
>>> loaded. Otherwise Hibernate is completely unusable due to poor
>>> performance with the 5*n+1 selects for every 'n' of the main entities
>>> it retrieves in a search, which has 5 1to1 associations.
>>>
>>> Thx.
>>>
>>> David
>>
>>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
Re: [Teneo] Use of constrained=true for 1 to 1? [message #427110 is a reply to message #427106] |
Mon, 02 February 2009 15:27 |
David Wynter Messages: 4624 Registered: July 2009 |
Senior Member |
|
|
Hi Martin,
Another question arises here. I changed one of the association to be
mandatory 1to1 like so
<xsd:element ecore:opposite="debtIssueData" minOccurs="1"
maxOccurs="1" ref="gensec:instrumentDomain">
<xsd:annotation>
<xsd:appinfo
source="teneo.jpa">@PrimaryKeyJoinColumn</xsd:appinfo>
<xsd:appinfo source="teneo.hibernate">@Fetch(JOIN)</xsd:appinfo>
</xsd:annotation>
</xsd:element>
But the dynamically generated mapping from the log shows this:
<one-to-one name="issueData" entity-name="IssueData"
cascade="merge,persist,save-update,lock,refresh" lazy="proxy"/>
<one-to-one name="underlyingCount" entity-name="UnderlyingCount"
cascade="merge,persist,save-update,lock,refresh" lazy="proxy"
property-ref="instrumentDomain"/>
<one-to-one name="lastCAE" entity-name="LastCAE"
cascade="merge,persist,save-update,lock,refresh" lazy="proxy"/>
<one-to-one name="debtIssueData" entity-name="DebtIssueData"
cascade="merge,persist,save-update,lock,refresh" lazy="proxy"/>
Therefore no difference from those that are optional and the one that is
mandatory?
Although this could be something else, as when I Reload... the genmodel
from the changed xsd, the timestamp on the genmodel file does not
change, almost as if it finds no differences in the xsd to load into the
genmodel? Changing to have minOccurs="1" and maxOccurs="1" makes it
mandatory doesn't it?
Thx.
David
Martin Taal wrote:
> Hi David,
> Constrained=true is only added if the association is required/mandatory.
> See here: http://www.hibernate.org/162.html and then specifically this
> remark on that page:
>
> So the resume: if your B->C mapping is mandatory (constrainted=true),
> Hibernate will use proxy for C resulting in lazy initialization. But if
> you allow B without C, Hibernate just HAS TO check presence of C at the
> moment it loads B. But a SELECT to check presence is just inefficient
> because the same SELECT may not just check presence, but load entire
> object. So lazy loading goes away.
>
> So I am wondering what would be a good other solution to solve this...
>
> Do you have control over the db schema, can you choose where to place
> the foreign key columns?
>
> gr. Martin
>
> David Wynter wrote:
>> Hi Martin,
>>
>> I use USE_PROXY ="true" and it marks all my one to one associations
>> with lazy="true". But because it does not also add constrained="true"
>> to the hbm.xml files these are always eagerly loaded. Is there a
>> reason you do not use constrained = "true"
>>
>> Also I have several one-to-one using PrimaryKeyJoinColumn, like so
>>
>> <xsd:element ecore:opposite="debtIssueData" minOccurs="0"
>> maxOccurs="1" ref="gensec:instrumentDomain">
>> <xsd:annotation>
>> <xsd:appinfo
>> source="teneo.jpa">@PrimaryKeyJoinColumn</xsd:appinfo>
>> <xsd:appinfo
>> source="teneo.hibernate">@Fetch(JOIN)</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>>
>> These should be optional and therefore I would like them to have
>> lazy="true" and constrained="true" as well. But they are lazy="false"
>>
>> <class name="com.stpenable.gensec.impl.DebtIssueDataImpl"
>> entity-name="DebtIssueData" abstract="false" lazy="false"
>> table="`debtissuedata`">
>> <meta attribute="eclassName">DebtIssueData</meta>
>> <meta attribute="epackage">http://www.stpenable.com/gensec</meta>
>> <id name="id" type="int" unsaved-value="-1">
>> <column not-null="true" unique="false" name="`id`"/>
>> <generator class="foreign">
>> <param name="property">instrumentDomain</param>
>> </generator>
>> </id>
>> ....
>>
>> How to I get it to make this lazy="true" constrained="true"?
>>
>> I need to absolutely control the loading of all entities using left
>> join fetch and inner join fetch in HQL, so want everything to be lazy
>> loaded. Otherwise Hibernate is completely unusable due to poor
>> performance with the 5*n+1 selects for every 'n' of the main entities
>> it retrieves in a search, which has 5 1to1 associations.
>>
>> Thx.
>>
>> David
>
>
|
|
|
Re: [Teneo] Use of constrained=true for 1 to 1? [message #427113 is a reply to message #427110] |
Mon, 02 February 2009 16:03 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi David,
Yes minOccurs="1" makes it mandatory.
I had a better look at the source code and the PrimaryKeyJoinColumn should force it to get constrained.
Can you put a breakpoint in the OneToOneMapper and then on this line:
boolean addConstrained = !paReference.getPrimaryKeyJoinColumns().isEmpty();
gr. Martin
David Wynter wrote:
> Hi Martin,
>
> Another question arises here. I changed one of the association to be
> mandatory 1to1 like so
> <xsd:element ecore:opposite="debtIssueData" minOccurs="1"
> maxOccurs="1" ref="gensec:instrumentDomain">
> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@PrimaryKeyJoinColumn</xsd:appinfo>
> <xsd:appinfo source="teneo.hibernate">@Fetch(JOIN)</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
>
> But the dynamically generated mapping from the log shows this:
> <one-to-one name="issueData" entity-name="IssueData"
> cascade="merge,persist,save-update,lock,refresh" lazy="proxy"/>
> <one-to-one name="underlyingCount" entity-name="UnderlyingCount"
> cascade="merge,persist,save-update,lock,refresh" lazy="proxy"
> property-ref="instrumentDomain"/>
> <one-to-one name="lastCAE" entity-name="LastCAE"
> cascade="merge,persist,save-update,lock,refresh" lazy="proxy"/>
> <one-to-one name="debtIssueData" entity-name="DebtIssueData"
> cascade="merge,persist,save-update,lock,refresh" lazy="proxy"/>
>
> Therefore no difference from those that are optional and the one that is
> mandatory?
>
> Although this could be something else, as when I Reload... the genmodel
> from the changed xsd, the timestamp on the genmodel file does not
> change, almost as if it finds no differences in the xsd to load into the
> genmodel? Changing to have minOccurs="1" and maxOccurs="1" makes it
> mandatory doesn't it?
>
> Thx.
>
> David
>
>
>
>
>
>
>
>
> Martin Taal wrote:
>> Hi David,
>> Constrained=true is only added if the association is
>> required/mandatory. See here: http://www.hibernate.org/162.html and
>> then specifically this remark on that page:
>>
>> So the resume: if your B->C mapping is mandatory (constrainted=true),
>> Hibernate will use proxy for C resulting in lazy initialization. But
>> if you allow B without C, Hibernate just HAS TO check presence of C at
>> the moment it loads B. But a SELECT to check presence is just
>> inefficient because the same SELECT may not just check presence, but
>> load entire object. So lazy loading goes away.
>>
>> So I am wondering what would be a good other solution to solve this...
>>
>> Do you have control over the db schema, can you choose where to place
>> the foreign key columns?
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi Martin,
>>>
>>> I use USE_PROXY ="true" and it marks all my one to one associations
>>> with lazy="true". But because it does not also add
>>> constrained="true" to the hbm.xml files these are always eagerly
>>> loaded. Is there a reason you do not use constrained = "true"
>>>
>>> Also I have several one-to-one using PrimaryKeyJoinColumn, like so
>>>
>>> <xsd:element ecore:opposite="debtIssueData" minOccurs="0"
>>> maxOccurs="1" ref="gensec:instrumentDomain">
>>> <xsd:annotation>
>>> <xsd:appinfo
>>> source="teneo.jpa">@PrimaryKeyJoinColumn</xsd:appinfo>
>>> <xsd:appinfo
>>> source="teneo.hibernate">@Fetch(JOIN)</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>>
>>> These should be optional and therefore I would like them to have
>>> lazy="true" and constrained="true" as well. But they are lazy="false"
>>>
>>> <class name="com.stpenable.gensec.impl.DebtIssueDataImpl"
>>> entity-name="DebtIssueData" abstract="false" lazy="false"
>>> table="`debtissuedata`">
>>> <meta attribute="eclassName">DebtIssueData</meta>
>>> <meta
>>> attribute="epackage">http://www.stpenable.com/gensec</meta>
>>> <id name="id" type="int" unsaved-value="-1">
>>> <column not-null="true" unique="false" name="`id`"/>
>>> <generator class="foreign">
>>> <param name="property">instrumentDomain</param>
>>> </generator>
>>> </id>
>>> ....
>>>
>>> How to I get it to make this lazy="true" constrained="true"?
>>>
>>> I need to absolutely control the loading of all entities using left
>>> join fetch and inner join fetch in HQL, so want everything to be lazy
>>> loaded. Otherwise Hibernate is completely unusable due to poor
>>> performance with the 5*n+1 selects for every 'n' of the main entities
>>> it retrieves in a search, which has 5 1to1 associations.
>>>
>>> Thx.
>>>
>>> David
>>
>>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
Goto Forum:
Current Time: Fri Apr 26 03:54:12 GMT 2024
Powered by FUDForum. Page generated in 0.03160 seconds
|