Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Re: [Teneo] Unable to use addEntity with Teneo generated code
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669197 is a reply to message #669181] Mon, 09 May 2011 12:49 Go to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
The query uses 2 aliases ins and ins_1_, I am not sure where this second alias is defined as the query does not show to
which table it applies. I guess it is a table which is joined to instrument some how, so ins_1_.instrument would be the
fk to instrument.

Does this sound familiar with anything in your model?

gr. Martin

On 05/09/2011 02:18 PM, David Wynter wrote:
> Hi,
>
> I found the work around bug 241537
>
> added this
> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>
>
> And modifying my query slightly to allow for the lowercase table name
> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM \"instrument\" {ins}").addEntity("ins", Instrument.class);
>
> I had forgotten to add all my 'favourite' Persistance Options. A dooh on my part.
>
> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY, "true");
> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY, "simple");
> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS, "false");
> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING, "true");
> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
> //ManyToOne and OneToMany are normally fetch eagerly, only if you do SET_PROXY=true then these are set to lazy
> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>
> However still not out of the woods I now get
>
> Column "INS_1_.instrument" not found; SQL statement:
> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as instrume5_182_0_, ins."tradingrestrictiontype" as
> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_, ins."contractvaluemultiplier" as contract8_182_0_,
> ins."createdate" as createdate9_182_0_, ins."defaultclause" as default10_182_0_, ins."firstamount" as firstam11_182_0_,
> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as firstde13_182_0_, ins."firsteventvalue" as
> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_, ins."isprimary" as isprimary16_182_0_, ins."lastamount"
> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_, ins."lasteventvalue" as lasteve19_182_0_,
> ins."marketderivedinfperiddration" as marketd20_182_0_, ins."marketderivedinfoperiodend" as marketd21_182_0_,
> ins."marketderivedinfoperiodstart" as marketd22_182_0_, ins."modifieddate" as modifie23_182_0_, ins."name" as
> name24_182_0_, ins."nextamount" as nextamount25_182_0_, ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_, ins."nmberholderspreviousdatetime" as
> nmberho29_182_0_, ins."objective" as objective30_182_0_, ins."penultimateamount" as penulti31_182_0_,
> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend" as princip33_182_0_, ins."principalpaymentstart" as
> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_, ins."qualifiedplans" as qualifi36_182_0_,
> ins."recurrable" as recurrable37_182_0_, ins."shortname" as shortname38_182_0_, ins."issuer" as issuer39_182_0_,
> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as calculat3_396_0_, ins_1_."indicatorstype" as
> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_, ins_1_."settlementtype" as settleme6_396_0_,
> ins_1_."quantitydescriptiontype" as quantity7_396_0_, ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_, ins_1_."valuationtype" as valuati11_396_0_,
> ins_1_."adjustedquantity" as adjuste12_396_0_, ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_, ins_1_."cashamount" as cashamount16_396_0_,
> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as current18_396_0_, ins_1_."dirtyprice" as
> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_, ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_, ins_1_."price" as price24_396_0_, ins_1_."quantity" as
> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_, ins_1_."valuationref" as valuati27_396_0_,
> ins_1_."weighting" as weighting28_396_0_, case when ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins [42122-146]
>
> There is no instrument column and I am wondering why it is looking for one?
>
> David
> On 09/05/11 13:02, David Wynter wrote:
>> Hi,
>>
>> I have used Teneo to build a large SQL database from an Annotated XSD. I
>> use Hibernate with Scalars to query the same database, this all works
>> fine. I now need to try to grab some entities from the database and use
>> them in a foreign key relationship associated with the persistence of a
>> related Entity.
>>
>> But I am getting an exception on this
>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM Instrument
>> {ins}").addEntity("ins", Instrument.class);
>> List instruments = query.list();
>>
>> I get
>> "Unknown entity: com.example.mddbyam.Instrument"
>>
>> I am running this in a JUnit test case and have done what is asked here
>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>
>> added the
>>
>> So I figure maybe I need a mapping file? I know it is supposed to do it
>> in memory, but clearly something is wrong there?
>>
>> I use the Teneo menu on the ecore file associated with my xsd source for
>> the schema and try to generate a mapping file I get this.
>>
>> An internal error occurred during: "Generate Mapping File".
>> java.lang.NullPointerException
>>
>> I have previously tried
>>
>> Query qury = session.createQuery("FROM Instrument");
>>
>> But that fails because I do not have a VERSION column, and it seems to
>> expect it.
>>
>> I just want all Instrument in the Db so I can later do a
>> "relatedEntity.setInstrument(instr);"
>>
>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>
>> Ideas?
>>
>> 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] Unable to use addEntity with Teneo generated code [message #669198 is a reply to message #669181] Mon, 09 May 2011 12:49 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
The query uses 2 aliases ins and ins_1_, I am not sure where this second alias is defined as the query does not show to
which table it applies. I guess it is a table which is joined to instrument some how, so ins_1_.instrument would be the
fk to instrument.

Does this sound familiar with anything in your model?

gr. Martin

On 05/09/2011 02:18 PM, David Wynter wrote:
> Hi,
>
> I found the work around bug 241537
>
> added this
> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>
>
> And modifying my query slightly to allow for the lowercase table name
> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM \"instrument\" {ins}").addEntity("ins", Instrument.class);
>
> I had forgotten to add all my 'favourite' Persistance Options. A dooh on my part.
>
> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY, "true");
> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY, "simple");
> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS, "false");
> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING, "true");
> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
> //ManyToOne and OneToMany are normally fetch eagerly, only if you do SET_PROXY=true then these are set to lazy
> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>
> However still not out of the woods I now get
>
> Column "INS_1_.instrument" not found; SQL statement:
> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as instrume5_182_0_, ins."tradingrestrictiontype" as
> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_, ins."contractvaluemultiplier" as contract8_182_0_,
> ins."createdate" as createdate9_182_0_, ins."defaultclause" as default10_182_0_, ins."firstamount" as firstam11_182_0_,
> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as firstde13_182_0_, ins."firsteventvalue" as
> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_, ins."isprimary" as isprimary16_182_0_, ins."lastamount"
> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_, ins."lasteventvalue" as lasteve19_182_0_,
> ins."marketderivedinfperiddration" as marketd20_182_0_, ins."marketderivedinfoperiodend" as marketd21_182_0_,
> ins."marketderivedinfoperiodstart" as marketd22_182_0_, ins."modifieddate" as modifie23_182_0_, ins."name" as
> name24_182_0_, ins."nextamount" as nextamount25_182_0_, ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_, ins."nmberholderspreviousdatetime" as
> nmberho29_182_0_, ins."objective" as objective30_182_0_, ins."penultimateamount" as penulti31_182_0_,
> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend" as princip33_182_0_, ins."principalpaymentstart" as
> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_, ins."qualifiedplans" as qualifi36_182_0_,
> ins."recurrable" as recurrable37_182_0_, ins."shortname" as shortname38_182_0_, ins."issuer" as issuer39_182_0_,
> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as calculat3_396_0_, ins_1_."indicatorstype" as
> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_, ins_1_."settlementtype" as settleme6_396_0_,
> ins_1_."quantitydescriptiontype" as quantity7_396_0_, ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_, ins_1_."valuationtype" as valuati11_396_0_,
> ins_1_."adjustedquantity" as adjuste12_396_0_, ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_, ins_1_."cashamount" as cashamount16_396_0_,
> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as current18_396_0_, ins_1_."dirtyprice" as
> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_, ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_, ins_1_."price" as price24_396_0_, ins_1_."quantity" as
> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_, ins_1_."valuationref" as valuati27_396_0_,
> ins_1_."weighting" as weighting28_396_0_, case when ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins [42122-146]
>
> There is no instrument column and I am wondering why it is looking for one?
>
> David
> On 09/05/11 13:02, David Wynter wrote:
>> Hi,
>>
>> I have used Teneo to build a large SQL database from an Annotated XSD. I
>> use Hibernate with Scalars to query the same database, this all works
>> fine. I now need to try to grab some entities from the database and use
>> them in a foreign key relationship associated with the persistence of a
>> related Entity.
>>
>> But I am getting an exception on this
>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM Instrument
>> {ins}").addEntity("ins", Instrument.class);
>> List instruments = query.list();
>>
>> I get
>> "Unknown entity: com.example.mddbyam.Instrument"
>>
>> I am running this in a JUnit test case and have done what is asked here
>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>
>> added the
>>
>> So I figure maybe I need a mapping file? I know it is supposed to do it
>> in memory, but clearly something is wrong there?
>>
>> I use the Teneo menu on the ecore file associated with my xsd source for
>> the schema and try to generate a mapping file I get this.
>>
>> An internal error occurred during: "Generate Mapping File".
>> java.lang.NullPointerException
>>
>> I have previously tried
>>
>> Query qury = session.createQuery("FROM Instrument");
>>
>> But that fails because I do not have a VERSION column, and it seems to
>> expect it.
>>
>> I just want all Instrument in the Db so I can later do a
>> "relatedEntity.setInstrument(instr);"
>>
>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>
>> Ideas?
>>
>> 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] Unable to use addEntity with Teneo generated code [message #669203 is a reply to message #669181] Mon, 09 May 2011 12:49 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
The query uses 2 aliases ins and ins_1_, I am not sure where this second alias is defined as the query does not show to
which table it applies. I guess it is a table which is joined to instrument some how, so ins_1_.instrument would be the
fk to instrument.

Does this sound familiar with anything in your model?

gr. Martin

On 05/09/2011 02:18 PM, David Wynter wrote:
> Hi,
>
> I found the work around bug 241537
>
> added this
> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>
>
> And modifying my query slightly to allow for the lowercase table name
> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM \"instrument\" {ins}").addEntity("ins", Instrument.class);
>
> I had forgotten to add all my 'favourite' Persistance Options. A dooh on my part.
>
> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY, "true");
> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY, "simple");
> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS, "false");
> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING, "true");
> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
> //ManyToOne and OneToMany are normally fetch eagerly, only if you do SET_PROXY=true then these are set to lazy
> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>
> However still not out of the woods I now get
>
> Column "INS_1_.instrument" not found; SQL statement:
> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as instrume5_182_0_, ins."tradingrestrictiontype" as
> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_, ins."contractvaluemultiplier" as contract8_182_0_,
> ins."createdate" as createdate9_182_0_, ins."defaultclause" as default10_182_0_, ins."firstamount" as firstam11_182_0_,
> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as firstde13_182_0_, ins."firsteventvalue" as
> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_, ins."isprimary" as isprimary16_182_0_, ins."lastamount"
> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_, ins."lasteventvalue" as lasteve19_182_0_,
> ins."marketderivedinfperiddration" as marketd20_182_0_, ins."marketderivedinfoperiodend" as marketd21_182_0_,
> ins."marketderivedinfoperiodstart" as marketd22_182_0_, ins."modifieddate" as modifie23_182_0_, ins."name" as
> name24_182_0_, ins."nextamount" as nextamount25_182_0_, ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_, ins."nmberholderspreviousdatetime" as
> nmberho29_182_0_, ins."objective" as objective30_182_0_, ins."penultimateamount" as penulti31_182_0_,
> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend" as princip33_182_0_, ins."principalpaymentstart" as
> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_, ins."qualifiedplans" as qualifi36_182_0_,
> ins."recurrable" as recurrable37_182_0_, ins."shortname" as shortname38_182_0_, ins."issuer" as issuer39_182_0_,
> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as calculat3_396_0_, ins_1_."indicatorstype" as
> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_, ins_1_."settlementtype" as settleme6_396_0_,
> ins_1_."quantitydescriptiontype" as quantity7_396_0_, ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_, ins_1_."valuationtype" as valuati11_396_0_,
> ins_1_."adjustedquantity" as adjuste12_396_0_, ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_, ins_1_."cashamount" as cashamount16_396_0_,
> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as current18_396_0_, ins_1_."dirtyprice" as
> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_, ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_, ins_1_."price" as price24_396_0_, ins_1_."quantity" as
> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_, ins_1_."valuationref" as valuati27_396_0_,
> ins_1_."weighting" as weighting28_396_0_, case when ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins [42122-146]
>
> There is no instrument column and I am wondering why it is looking for one?
>
> David
> On 09/05/11 13:02, David Wynter wrote:
>> Hi,
>>
>> I have used Teneo to build a large SQL database from an Annotated XSD. I
>> use Hibernate with Scalars to query the same database, this all works
>> fine. I now need to try to grab some entities from the database and use
>> them in a foreign key relationship associated with the persistence of a
>> related Entity.
>>
>> But I am getting an exception on this
>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM Instrument
>> {ins}").addEntity("ins", Instrument.class);
>> List instruments = query.list();
>>
>> I get
>> "Unknown entity: com.example.mddbyam.Instrument"
>>
>> I am running this in a JUnit test case and have done what is asked here
>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>
>> added the
>>
>> So I figure maybe I need a mapping file? I know it is supposed to do it
>> in memory, but clearly something is wrong there?
>>
>> I use the Teneo menu on the ecore file associated with my xsd source for
>> the schema and try to generate a mapping file I get this.
>>
>> An internal error occurred during: "Generate Mapping File".
>> java.lang.NullPointerException
>>
>> I have previously tried
>>
>> Query qury = session.createQuery("FROM Instrument");
>>
>> But that fails because I do not have a VERSION column, and it seems to
>> expect it.
>>
>> I just want all Instrument in the Db so I can later do a
>> "relatedEntity.setInstrument(instr);"
>>
>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>
>> Ideas?
>>
>> 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] Unable to use addEntity with Teneo generated code [message #669204 is a reply to message #669197] Mon, 09 May 2011 13:11 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
OK, I realise that I had added an extension for Instrument

Like so:

<xsd:complexType name="Underlying">
<xsd:complexContent>
<xsd:extension base="mddbyam:Instrument">

It seems to be getting the Underlying attributes in the projection but
not including the table in the table list. My preference is not to get
the extension columns. Does this mean I cannot use the xsd:extension
element type?

Thx.

David


On 09/05/11 13:49, Martin Taal wrote:
> Hi David,
> The query uses 2 aliases ins and ins_1_, I am not sure where this second
> alias is defined as the query does not show to which table it applies. I
> guess it is a table which is joined to instrument some how, so
> ins_1_.instrument would be the fk to instrument.
>
> Does this sound familiar with anything in your model?
>
> gr. Martin
>
> On 05/09/2011 02:18 PM, David Wynter wrote:
>> Hi,
>>
>> I found the work around bug 241537
>>
>> added this
>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>
>>
>>
>> And modifying my query slightly to allow for the lowercase table name
>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>
>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>> on my part.
>>
>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY, "true");
>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>> "simple");
>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>> "false");
>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING, "true");
>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>> SET_PROXY=true then these are set to lazy
>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>
>> However still not out of the woods I now get
>>
>> Column "INS_1_.instrument" not found; SQL statement:
>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>> instrume5_182_0_, ins."tradingrestrictiontype" as
>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>> ins."contractvaluemultiplier" as contract8_182_0_,
>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>> firstde13_182_0_, ins."firsteventvalue" as
>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>> ins."lasteventvalue" as lasteve19_182_0_,
>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>> ins."nmberholderspreviousdatetime" as
>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>> ins."penultimateamount" as penulti31_182_0_,
>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>> as princip33_182_0_, ins."principalpaymentstart" as
>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>> ins."qualifiedplans" as qualifi36_182_0_,
>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>> calculat3_396_0_, ins_1_."indicatorstype" as
>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>> ins_1_."settlementtype" as settleme6_396_0_,
>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>> ins_1_."valuationtype" as valuati11_396_0_,
>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>> ins_1_."cashamount" as cashamount16_396_0_,
>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>> current18_396_0_, ins_1_."dirtyprice" as
>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>> ins_1_."valuationref" as valuati27_396_0_,
>> ins_1_."weighting" as weighting28_396_0_, case when
>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>> [42122-146]
>>
>> There is no instrument column and I am wondering why it is looking for
>> one?
>>
>> David
>> On 09/05/11 13:02, David Wynter wrote:
>>> Hi,
>>>
>>> I have used Teneo to build a large SQL database from an Annotated XSD. I
>>> use Hibernate with Scalars to query the same database, this all works
>>> fine. I now need to try to grab some entities from the database and use
>>> them in a foreign key relationship associated with the persistence of a
>>> related Entity.
>>>
>>> But I am getting an exception on this
>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM Instrument
>>> {ins}").addEntity("ins", Instrument.class);
>>> List instruments = query.list();
>>>
>>> I get
>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>
>>> I am running this in a JUnit test case and have done what is asked here
>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>
>>>
>>> added the
>>>
>>> So I figure maybe I need a mapping file? I know it is supposed to do it
>>> in memory, but clearly something is wrong there?
>>>
>>> I use the Teneo menu on the ecore file associated with my xsd source for
>>> the schema and try to generate a mapping file I get this.
>>>
>>> An internal error occurred during: "Generate Mapping File".
>>> java.lang.NullPointerException
>>>
>>> I have previously tried
>>>
>>> Query qury = session.createQuery("FROM Instrument");
>>>
>>> But that fails because I do not have a VERSION column, and it seems to
>>> expect it.
>>>
>>> I just want all Instrument in the Db so I can later do a
>>> "relatedEntity.setInstrument(instr);"
>>>
>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>
>>> Ideas?
>>>
>>> Thx.
>>>
>>> David
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669227 is a reply to message #669204] Mon, 09 May 2011 14:22 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hmm this seems like a Hibernate bug, right? The table should be listed in the from (joined to the main table). How does
the generated hbm look like?

If you don't want Underlying to be mapped at all then you should add @Transient to the complexType as an annotation.
If Underlying is mapped then it is difficult to prevent Hibernate from fetching the columns, as it does not know upfront
what type to instantiate without getting the subclass columns.

gr. Martin

On 05/09/2011 03:11 PM, David Wynter wrote:
> OK, I realise that I had added an extension for Instrument
>
> Like so:
>
> <xsd:complexType name="Underlying">
> <xsd:complexContent>
> <xsd:extension base="mddbyam:Instrument">
>
> It seems to be getting the Underlying attributes in the projection but not including the table in the table list. My
> preference is not to get the extension columns. Does this mean I cannot use the xsd:extension element type?
>
> Thx.
>
> David
>
>
> On 09/05/11 13:49, Martin Taal wrote:
>> Hi David,
>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>> alias is defined as the query does not show to which table it applies. I
>> guess it is a table which is joined to instrument some how, so
>> ins_1_.instrument would be the fk to instrument.
>>
>> Does this sound familiar with anything in your model?
>>
>> gr. Martin
>>
>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>> Hi,
>>>
>>> I found the work around bug 241537
>>>
>>> added this
>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>
>>>
>>>
>>>
>>> And modifying my query slightly to allow for the lowercase table name
>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>
>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>> on my part.
>>>
>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY, "true");
>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>> "simple");
>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>> "false");
>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING, "true");
>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>> SET_PROXY=true then these are set to lazy
>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>
>>> However still not out of the woods I now get
>>>
>>> Column "INS_1_.instrument" not found; SQL statement:
>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>> firstde13_182_0_, ins."firsteventvalue" as
>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>> ins."lasteventvalue" as lasteve19_182_0_,
>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>> ins."nmberholderspreviousdatetime" as
>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>> ins."penultimateamount" as penulti31_182_0_,
>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>> as princip33_182_0_, ins."principalpaymentstart" as
>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>> ins."qualifiedplans" as qualifi36_182_0_,
>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>> ins_1_."settlementtype" as settleme6_396_0_,
>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>> ins_1_."valuationtype" as valuati11_396_0_,
>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>> ins_1_."cashamount" as cashamount16_396_0_,
>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>> current18_396_0_, ins_1_."dirtyprice" as
>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>> ins_1_."valuationref" as valuati27_396_0_,
>>> ins_1_."weighting" as weighting28_396_0_, case when
>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>> [42122-146]
>>>
>>> There is no instrument column and I am wondering why it is looking for
>>> one?
>>>
>>> David
>>> On 09/05/11 13:02, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I have used Teneo to build a large SQL database from an Annotated XSD. I
>>>> use Hibernate with Scalars to query the same database, this all works
>>>> fine. I now need to try to grab some entities from the database and use
>>>> them in a foreign key relationship associated with the persistence of a
>>>> related Entity.
>>>>
>>>> But I am getting an exception on this
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM Instrument
>>>> {ins}").addEntity("ins", Instrument.class);
>>>> List instruments = query.list();
>>>>
>>>> I get
>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>
>>>> I am running this in a JUnit test case and have done what is asked here
>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>
>>>>
>>>>
>>>> added the
>>>>
>>>> So I figure maybe I need a mapping file? I know it is supposed to do it
>>>> in memory, but clearly something is wrong there?
>>>>
>>>> I use the Teneo menu on the ecore file associated with my xsd source for
>>>> the schema and try to generate a mapping file I get this.
>>>>
>>>> An internal error occurred during: "Generate Mapping File".
>>>> java.lang.NullPointerException
>>>>
>>>> I have previously tried
>>>>
>>>> Query qury = session.createQuery("FROM Instrument");
>>>>
>>>> But that fails because I do not have a VERSION column, and it seems to
>>>> expect it.
>>>>
>>>> I just want all Instrument in the Db so I can later do a
>>>> "relatedEntity.setInstrument(instr);"
>>>>
>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>
>>>> Ideas?
>>>>
>>>> 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] Unable to use addEntity with Teneo generated code [message #669256 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669260 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669261 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669263 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669266 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669269 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669277 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669285 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669286 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669290 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669292 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669294 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669300 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669304 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669308 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669310 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669313 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669314 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669315 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669316 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669317 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669319 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669323 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669326 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669329 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669330 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669332 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669333 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669334 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669335 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669336 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669337 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669338 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669339 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669342 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669343 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669346 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669347 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669348 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669349 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669350 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669351 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669352 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669353 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669354 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669355 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669356 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669359 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669361 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669363 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669367 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669375 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669378 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669382 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669388 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669389 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669407 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669408 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669409 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669411 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669412 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669415 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669418 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669428 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669429 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669431 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669432 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669433 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669436 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669440 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669441 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669443 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669444 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669447 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669449 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669451 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669460 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669466 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669470 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669477 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669480 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669481 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669495 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669497 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669510 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669511 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669512 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669527 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669528 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669539 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669541 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669542 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669543 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669544 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669549 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669551 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669552 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669555 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669559 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669564 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669567 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669569 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669573 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669579 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669580 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669582 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669584 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669586 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669590 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669592 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669593 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669595 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669596 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669600 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669601 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669602 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669604 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669605 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669608 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669609 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669610 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669611 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669614 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669615 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669617 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669618 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669627 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669628 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669629 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669630 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669631 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669634 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669635 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669636 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669637 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669638 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669641 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669642 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669644 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669645 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669646 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669647 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669648 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669650 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669651 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669652 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669653 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669654 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669657 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669659 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669661 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669664 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669665 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669670 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669672 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669673 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669676 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669678 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669688 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669691 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669692 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669706 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669708 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669709 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669712 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669720 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669722 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669726 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669727 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669728 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669731 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669733 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669736 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669740 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669744 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669745 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669748 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669750 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669753 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669755 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669760 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669765 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669767 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669774 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669775 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669777 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669792 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669794 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669795 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669797 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669798 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669808 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669809 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669818 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Re: [Teneo] Unable to use addEntity with Teneo generated code [message #669830 is a reply to message #669227] Mon, 09 May 2011 15:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Yes this seems like a Hibernate bug to me. I hate the way they presume I
would want the subclass (if that is what you end up with when using the
xsd:Extension) every time and give me no option to prevent Hibernate
fetching it.

I had that NPE when I tried to generate the hbm, see the original email.

In the end using JDBCTemplate was a much simpler solution, so given my
time constraints I abandoned Hibernate.

Thx. for your advice.

David

On 09/05/11 15:22, Martin Taal wrote:
> Hmm this seems like a Hibernate bug, right? The table should be listed
> in the from (joined to the main table). How does the generated hbm look
> like?
>
> If you don't want Underlying to be mapped at all then you should add
> @Transient to the complexType as an annotation.
> If Underlying is mapped then it is difficult to prevent Hibernate from
> fetching the columns, as it does not know upfront what type to
> instantiate without getting the subclass columns.
>
> gr. Martin
>
> On 05/09/2011 03:11 PM, David Wynter wrote:
>> OK, I realise that I had added an extension for Instrument
>>
>> Like so:
>>
>> <xsd:complexType name="Underlying">
>> <xsd:complexContent>
>> <xsd:extension base="mddbyam:Instrument">
>>
>> It seems to be getting the Underlying attributes in the projection but
>> not including the table in the table list. My
>> preference is not to get the extension columns. Does this mean I
>> cannot use the xsd:extension element type?
>>
>> Thx.
>>
>> David
>>
>>
>> On 09/05/11 13:49, Martin Taal wrote:
>>> Hi David,
>>> The query uses 2 aliases ins and ins_1_, I am not sure where this second
>>> alias is defined as the query does not show to which table it applies. I
>>> guess it is a table which is joined to instrument some how, so
>>> ins_1_.instrument would be the fk to instrument.
>>>
>>> Does this sound familiar with anything in your model?
>>>
>>> gr. Martin
>>>
>>> On 05/09/2011 02:18 PM, David Wynter wrote:
>>>> Hi,
>>>>
>>>> I found the work around bug 241537
>>>>
>>>> added this
>>>> hbds.getExtensionManager().registerExtension(EntityNameStrat egy.class.getName(),EntityInterfaceNameStrategy.class.getNam e());
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> And modifying my query slightly to allow for the lowercase table name
>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>> \"instrument\" {ins}").addEntity("ins", Instrument.class);
>>>>
>>>> I had forgotten to add all my 'favourite' Persistance Options. A dooh
>>>> on my part.
>>>>
>>>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH , "28");
>>>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME , "id");
>>>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>>>> "simple");
>>>> props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONT AINED_ASSOCIATIONS,
>>>>
>>>> "false");
>>>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>>>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING,
>>>> "true");
>>>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>>>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
>>>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>>>> props.setProperty(PersistenceOptions.XSDDATE_CLASS, "java.util.Date");
>>>> //ManyToOne and OneToMany are normally fetch eagerly, only if you do
>>>> SET_PROXY=true then these are set to lazy
>>>> props.setProperty(PersistenceOptions.SET_PROXY, "true");
>>>>
>>>> However still not out of the woods I now get
>>>>
>>>> Column "INS_1_.instrument" not found; SQL statement:
>>>> SELECT ins."id" as id1_182_0_, ins."listmethodtype" as
>>>> listmeth2_182_0_, ins."marketstatus_type" as marketst3_182_0_,
>>>> ins."marketstatus_id" as marketst4_182_0_, ins."instrumentformtype" as
>>>> instrume5_182_0_, ins."tradingrestrictiontype" as
>>>> tradingr6_182_0_, ins."benchmarkstrategy" as benchmar7_182_0_,
>>>> ins."contractvaluemultiplier" as contract8_182_0_,
>>>> ins."createdate" as createdate9_182_0_, ins."defaultclause" as
>>>> default10_182_0_, ins."firstamount" as firstam11_182_0_,
>>>> ins."firstdate" as firstdate12_182_0_, ins."firstdealingdate" as
>>>> firstde13_182_0_, ins."firsteventvalue" as
>>>> firstev14_182_0_, ins."firstsettlementdate" as firstse15_182_0_,
>>>> ins."isprimary" as isprimary16_182_0_, ins."lastamount"
>>>> as lastamount17_182_0_, ins."lastdate" as lastdate18_182_0_,
>>>> ins."lasteventvalue" as lasteve19_182_0_,
>>>> ins."marketderivedinfperiddration" as marketd20_182_0_,
>>>> ins."marketderivedinfoperiodend" as marketd21_182_0_,
>>>> ins."marketderivedinfoperiodstart" as marketd22_182_0_,
>>>> ins."modifieddate" as modifie23_182_0_, ins."name" as
>>>> name24_182_0_, ins."nextamount" as nextamount25_182_0_,
>>>> ins."nexteventvalue" as nexteve26_182_0_, ins."numberholders" as
>>>> numberh27_182_0_, ins."numberholdersdatetime" as numberh28_182_0_,
>>>> ins."nmberholderspreviousdatetime" as
>>>> nmberho29_182_0_, ins."objective" as objective30_182_0_,
>>>> ins."penultimateamount" as penulti31_182_0_,
>>>> ins."penultimatedate" as penulti32_182_0_, ins."principalpaymentend"
>>>> as princip33_182_0_, ins."principalpaymentstart" as
>>>> princip34_182_0_, ins."purchasingminimums" as purchas35_182_0_,
>>>> ins."qualifiedplans" as qualifi36_182_0_,
>>>> ins."recurrable" as recurrable37_182_0_, ins."shortname" as
>>>> shortname38_182_0_, ins."issuer" as issuer39_182_0_,
>>>> ins_1_."instrument" as instrument2_396_0_, ins_1_."calculationtype" as
>>>> calculat3_396_0_, ins_1_."indicatorstype" as
>>>> indicato4_396_0_, ins_1_."fxratecalctype" as fxrateca5_396_0_,
>>>> ins_1_."settlementtype" as settleme6_396_0_,
>>>> ins_1_."quantitydescriptiontype" as quantity7_396_0_,
>>>> ins_1_."quantitytype" as quantity8_396_0_, ins_1_."unittype" as
>>>> unittype9_396_0_, ins_1_."cashtype" as cashtype10_396_0_,
>>>> ins_1_."valuationtype" as valuati11_396_0_,
>>>> ins_1_."adjustedquantity" as adjuste12_396_0_,
>>>> ins_1_."allocatepercent" as allocat13_396_0_, ins_1_."basevalue" as
>>>> basevalue14_396_0_, ins_1_."capvalue" as capvalue15_396_0_,
>>>> ins_1_."cashamount" as cashamount16_396_0_,
>>>> ins_1_."componentvalue" as compone17_396_0_, ins_1_."currentvalue" as
>>>> current18_396_0_, ins_1_."dirtyprice" as
>>>> dirtyprice19_396_0_, ins_1_."endprice" as endprice20_396_0_,
>>>> ins_1_."endvalue" as endvalue21_396_0_, ins_1_."fxrate" as
>>>> fxrate22_396_0_, ins_1_."multiplier" as multiplier23_396_0_,
>>>> ins_1_."price" as price24_396_0_, ins_1_."quantity" as
>>>> quantity25_396_0_, ins_1_."startvalue" as startvalue26_396_0_,
>>>> ins_1_."valuationref" as valuati27_396_0_,
>>>> ins_1_."weighting" as weighting28_396_0_, case when
>>>> ins_1_."cm_exmpl_mddbym_instrment_id" is not null then 1 when
>>>> ins."id" is not null then 0 end as clazz_0_ FROM "instrument" ins
>>>> [42122-146]
>>>>
>>>> There is no instrument column and I am wondering why it is looking for
>>>> one?
>>>>
>>>> David
>>>> On 09/05/11 13:02, David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I have used Teneo to build a large SQL database from an Annotated
>>>>> XSD. I
>>>>> use Hibernate with Scalars to query the same database, this all works
>>>>> fine. I now need to try to grab some entities from the database and
>>>>> use
>>>>> them in a foreign key relationship associated with the persistence
>>>>> of a
>>>>> related Entity.
>>>>>
>>>>> But I am getting an exception on this
>>>>> SQLQuery query = session.createSQLQuery("SELECT {ins.*} FROM
>>>>> Instrument
>>>>> {ins}").addEntity("ins", Instrument.class);
>>>>> List instruments = query.list();
>>>>>
>>>>> I get
>>>>> "Unknown entity: com.example.mddbyam.Instrument"
>>>>>
>>>>> I am running this in a JUnit test case and have done what is asked
>>>>> here
>>>>> http://wiki.eclipse.org/Teneo/Hibernate/Download_and_Install #Teneo.2C_import-packages_and_ClassNotFoundException_when_ru nning_junit_testcaseshave
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> added the
>>>>>
>>>>> So I figure maybe I need a mapping file? I know it is supposed to
>>>>> do it
>>>>> in memory, but clearly something is wrong there?
>>>>>
>>>>> I use the Teneo menu on the ecore file associated with my xsd
>>>>> source for
>>>>> the schema and try to generate a mapping file I get this.
>>>>>
>>>>> An internal error occurred during: "Generate Mapping File".
>>>>> java.lang.NullPointerException
>>>>>
>>>>> I have previously tried
>>>>>
>>>>> Query qury = session.createQuery("FROM Instrument");
>>>>>
>>>>> But that fails because I do not have a VERSION column, and it seems to
>>>>> expect it.
>>>>>
>>>>> I just want all Instrument in the Db so I can later do a
>>>>> "relatedEntity.setInstrument(instr);"
>>>>>
>>>>> I am using Hibernate 3.6 with Teneo 1.1.2 V201101061255 plugin
>>>>>
>>>>> Ideas?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>
>>>
>>
>
>
Previous Topic:Import XMI files into database
Next Topic:Re: EMF model editing /persistence in a &quot;typical&quot; RCP/IDE app
Goto Forum:
  


Current Time: Thu Mar 28 22:04:06 GMT 2024

Powered by FUDForum. Page generated in 0.24596 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top