Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » [Teneo] Possible to Override Generation of hibernate.hbm.xml?
[Teneo] Possible to Override Generation of hibernate.hbm.xml? [message #72941] |
Tue, 27 February 2007 16:15 |
Eclipse User |
|
|
|
Originally posted by: bsu.bergauer.ch
Hi,
I have some problems getting in control of the id and version columns in my
project. I need to have those attributes both in the ecore and in my model
interface (non synthetic), in the EMF-Editor, however, they are not visible.
I tried to set persistency annotations in the model interfaces with little
success:
FOR THE ID COLUMN:
/**
* @model id="true" required="true"
* @generated
*/
@Id @GeneratedValue(strategy=GenerationType.AUTO)
int getId();
/**
* @generated
*/
void setId(int value);
RESULT: org.hibernate.id.IdentifierGenerationException: ids for this class
must be manually assigned before calling save()
(I notice that the generated PK `id` is auto_increment in
MySql)
FOR THE VERSION COLUMN:
/**
* @model required="true"
* @generated
*/
@Version
int getVersion();
/**
* @generated
*/
void setVersion(int value);
RESULT: org.hibernate.MappingException: Duplicate property mapping of
version found
As I will have quite some tables in my model I'm not so keen in modifying
all generated model interfaces in order to add any annotations. What I
rather would like is to utilize the Teneo utility and so generate EMF -
Hibernate OR mapping direct from the ecore file. In order to do that I have
added persistenceProperties.setProperty(PersistenceOptions.USE_MAP PING_FILE,
"true"); to the persistency property in the EditorPlugin. The generated
hibernate.hbm.xml has anyway to be modified in the following way:
GENERATED:
<id name="id" type="int">
<column not-null="true" unique="false" name="`id`"/>
</id>
MODIFIED:
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="identity"/>
</id>
GENERATED:
<version name="version" column="version"
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
ler">
<meta attribute="syntheticVersion">true</meta>
</version>
MODIFIED:
<version name="version" column="version"
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
ler"/>
With the above modifications my EMF-Editor is working and I have no problems
persisting the model objects to the database. Ids are generated and version
is incremented.
My question is if one somehow can override the mappings being generated in
order to achieve above modified id- and version-elements?
Thanks,
Bj
|
|
|
Re: [Teneo] Possible to Override Generation of hibernate.hbm.xml? [message #72985 is a reply to message #72941] |
Tue, 27 February 2007 17:06 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Björn,
In Teneo annotations are not specified in the java code but in the model (ecore or xsd) or in a
separate xml.
So the @Id and @GeneratedValue(strategy=GenerationType.AUTO) annotations should be specified there.
If your id attributes all use an EDataType defined by yourselve then you can add the annotations to
the EDataType (so one place instead of at each attribute).
See also here:
http://www.elver.org/hibernate/ejb3_format.html
http://www.elver.org/hibernate/ejb3_examples.html
gr. Martin
Björn Sundin wrote:
> Hi,
>
> I have some problems getting in control of the id and version columns in my
> project. I need to have those attributes both in the ecore and in my model
> interface (non synthetic), in the EMF-Editor, however, they are not visible.
>
> I tried to set persistency annotations in the model interfaces with little
> success:
>
> FOR THE ID COLUMN:
> /**
> * @model id="true" required="true"
> * @generated
> */
> @Id @GeneratedValue(strategy=GenerationType.AUTO)
> int getId();
>
> /**
> * @generated
> */
> void setId(int value);
>
> RESULT: org.hibernate.id.IdentifierGenerationException: ids for this class
> must be manually assigned before calling save()
> (I notice that the generated PK `id` is auto_increment in
> MySql)
>
> FOR THE VERSION COLUMN:
> /**
> * @model required="true"
> * @generated
> */
> @Version
> int getVersion();
>
> /**
> * @generated
> */
> void setVersion(int value);
>
> RESULT: org.hibernate.MappingException: Duplicate property mapping of
> version found
>
> As I will have quite some tables in my model I'm not so keen in modifying
> all generated model interfaces in order to add any annotations. What I
> rather would like is to utilize the Teneo utility and so generate EMF -
> Hibernate OR mapping direct from the ecore file. In order to do that I have
> added persistenceProperties.setProperty(PersistenceOptions.USE_MAP PING_FILE,
> "true"); to the persistency property in the EditorPlugin. The generated
> hibernate.hbm.xml has anyway to be modified in the following way:
>
> GENERATED:
> <id name="id" type="int">
> <column not-null="true" unique="false" name="`id`"/>
> </id>
>
> MODIFIED:
> <id name="id" type="int" column="id" unsaved-value="0">
> <generator class="identity"/>
> </id>
>
> GENERATED:
> <version name="version" column="version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
> ler">
> <meta attribute="syntheticVersion">true</meta>
> </version>
>
> MODIFIED:
> <version name="version" column="version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
> ler"/>
>
> With the above modifications my EMF-Editor is working and I have no problems
> persisting the model objects to the database. Ids are generated and version
> is incremented.
>
> My question is if one somehow can override the mappings being generated in
> order to achieve above modified id- and version-elements?
>
> Thanks,
> Björn
>
> PS. Versions used and settings:
> - Eclipse IDE 3.2.1
> - EMF 2.2.2
> - Teneo 0.7.5 Maintenance Build
> - Hibernate 3.2
> - MySql and/or Derby embedded
> - Persistence properties set in the EditorPlugin:
>
> persistenceProperties.setProperty(PersistenceOptions.ID_COLU MN_NAME, "id");
>
> persistenceProperties.setProperty(PersistenceOptions.VERSION _COLUMN_NAME,
> "version");
>
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Possible to Override Generation of hibernate.hbm.xml? [message #72995 is a reply to message #72985] |
Wed, 28 February 2007 13:50 |
Eclipse User |
|
|
|
Originally posted by: bsu.bergauer.ch
Hi Martin,
Thanks for your reply. It definitely brought me on the right path and so I
decided to define my own id and version datatypes in ecore:
<eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
instanceClassName="int">
<eAnnotations source="teneo.jpa/Id">
<details key="appinfo"
value="@GeneratedValue(strategy="AUTO")"/ >
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
instanceClassName="int">
<eAnnotations source="teneo.jpa/Version">
<!-- <details key="appinfo" value="@Version"/> -->
</eAnnotations>
</eClassifiers>
Those two datatypes are referenced in i.e StatusType:
<eClassifiers xsi:type="ecore:EClass" name="StatusType">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
lowerBound="1"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
lowerBound="1"
eType="#//bergauer/rcp/amset/model/datatypes/AmsetId"
iD="true"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="version"
lowerBound="1"
eType="#//bergauer/rcp/amset/model/datatypes/AmsetVersion"/ >
</eClassifiers>
I now have the following results:
PersistenceOptions.USE_MAPPING_FILE set true:
- The hibernate.hbm.xml I now have the id-element with generator,
non-synthetic. Id is generated as expected
- The version attribute that I define in ecore isn't recognized with
annotation yet. In the hibernate.hbm.xml I have one version-element (with
synthetic set true) and in the database I get two fields e_version and
version. The PersistenceOptions.ALWAYS_VERSION is set false in the
EditorPlugin.
<class entity-name="StatusType" abstract="false" lazy="false"
discriminator-value="StatusType" table="`statustype`">
<meta attribute="eclassName">StatusType</meta>
<meta
attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
/meta>
<id name="id" type="int">
<column not-null="true" unique="false" name="`id`"/>
<generator class="native"/>
</id>
<discriminator column="`dtype`" type="string"/>
<version name="e_version" column="e_version"
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
ler">
<meta attribute="syntheticVersion">true</meta>
</version>
<property name="name" lazy="false" insert="true" update="true"
not-null="true" unique="false" type="java.lang.String">
<column not-null="true" unique="false" name="`name`"/>
</property>
</class>
PersistenceOptions.USE_MAPPING_FILE set false:
Neither id nor version work is reqognized. In the in-menory mapping I
have no generator element for the id-element:
<class entity-name="StatusType" abstract="false" lazy="false"
discriminator-value="StatusType" table="`statustype`">
<meta attribute="eclassName">StatusType</meta>
<meta
attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
/meta>
<id name="id" type="int">
<column not-null="true" unique="false" name="`id`"/>
</id>
<discriminator column="`dtype`" type="string"/>
<property name="name" lazy="false" insert="true" update="true"
not-null="true" unique="false" type="java.lang.String">
<column not-null="true" unique="false" name="`name`"/>
</property>
<property name="version" lazy="false" insert="true" update="true"
not-null="true" unique="false" type="int">
<column not-null="true" unique="false" name="`version`"/>
</property>
</class>
The solution using the hibernate.hbm.xml seems to be the better way, so I
think I will go on using PersistenceOptions.USE_MAPPING_FILE=true.
Apperently I'm doing something wrong with the version though. Am I
overlooking something obvious?
cheers,
Bj
|
|
|
Re: [Teneo] Possible to Override Generation of hibernate.hbm.xml? [message #73013 is a reply to message #72995] |
Wed, 28 February 2007 14:16 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Björn,
Afaics the <details...> tag in the eAnnotations of the AmsetVersion EDataType is commented out using
xml comment characters (<!-- and -->). Could that be a reason?
Also the id annotation does not seem to be completely correct. The source should teneo.jpa and then
the value should also contain the @Id annotation.
There should be no difference in generating the mapping file manually and then use that or the
automatic mapping in-memory (it also generates an in-memory mapping). I would suggest to use the
automatic in-memory mapping until you want to do extensive manual changes (for example to map to a
current db schema).
gr. Martin
Björn Sundin wrote:
> Hi Martin,
>
> Thanks for your reply. It definitely brought me on the right path and so I
> decided to define my own id and version datatypes in ecore:
>
> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
> instanceClassName="int">
> <eAnnotations source="teneo.jpa/Id">
> <details key="appinfo"
> value="@GeneratedValue(strategy="AUTO")"/ >
> </eAnnotations>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
> instanceClassName="int">
> <eAnnotations source="teneo.jpa/Version">
> <!-- <details key="appinfo" value="@Version"/> -->
> </eAnnotations>
> </eClassifiers>
>
> Those two datatypes are referenced in i.e StatusType:
>
> <eClassifiers xsi:type="ecore:EClass" name="StatusType">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> lowerBound="1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
> lowerBound="1"
> eType="#//bergauer/rcp/amset/model/datatypes/AmsetId"
> iD="true"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="version"
> lowerBound="1"
> eType="#//bergauer/rcp/amset/model/datatypes/AmsetVersion"/ >
> </eClassifiers>
>
>
> I now have the following results:
>
> PersistenceOptions.USE_MAPPING_FILE set true:
> - The hibernate.hbm.xml I now have the id-element with generator,
> non-synthetic. Id is generated as expected
> - The version attribute that I define in ecore isn't recognized with
> annotation yet. In the hibernate.hbm.xml I have one version-element (with
> synthetic set true) and in the database I get two fields e_version and
> version. The PersistenceOptions.ALWAYS_VERSION is set false in the
> EditorPlugin.
>
> <class entity-name="StatusType" abstract="false" lazy="false"
> discriminator-value="StatusType" table="`statustype`">
> <meta attribute="eclassName">StatusType</meta>
> <meta
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
> /meta>
> <id name="id" type="int">
> <column not-null="true" unique="false" name="`id`"/>
> <generator class="native"/>
> </id>
> <discriminator column="`dtype`" type="string"/>
> <version name="e_version" column="e_version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
> ler">
> <meta attribute="syntheticVersion">true</meta>
> </version>
> <property name="name" lazy="false" insert="true" update="true"
> not-null="true" unique="false" type="java.lang.String">
> <column not-null="true" unique="false" name="`name`"/>
> </property>
> </class>
>
> PersistenceOptions.USE_MAPPING_FILE set false:
> Neither id nor version work is reqognized. In the in-menory mapping I
> have no generator element for the id-element:
>
> <class entity-name="StatusType" abstract="false" lazy="false"
> discriminator-value="StatusType" table="`statustype`">
> <meta attribute="eclassName">StatusType</meta>
> <meta
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
> /meta>
> <id name="id" type="int">
> <column not-null="true" unique="false" name="`id`"/>
> </id>
> <discriminator column="`dtype`" type="string"/>
> <property name="name" lazy="false" insert="true" update="true"
> not-null="true" unique="false" type="java.lang.String">
> <column not-null="true" unique="false" name="`name`"/>
> </property>
> <property name="version" lazy="false" insert="true" update="true"
> not-null="true" unique="false" type="int">
> <column not-null="true" unique="false" name="`version`"/>
> </property>
> </class>
>
> The solution using the hibernate.hbm.xml seems to be the better way, so I
> think I will go on using PersistenceOptions.USE_MAPPING_FILE=true.
> Apperently I'm doing something wrong with the version though. Am I
> overlooking something obvious?
>
> cheers,
> Björn
>
> ref: [Teneo] Setting Id generator from ecore file
> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
> news:es1oej$v6h$1@utils.eclipse.org...
>> Hi Björn,
>> In Teneo annotations are not specified in the java code but in the model
> (ecore or xsd) or in a
>> separate xml.
>> So the @Id and @GeneratedValue(strategy=GenerationType.AUTO) annotations
> should be specified there.
>> If your id attributes all use an EDataType defined by yourselve then you
> can add the annotations to
>> the EDataType (so one place instead of at each attribute).
>>
>> See also here:
>> http://www.elver.org/hibernate/ejb3_format.html
>> http://www.elver.org/hibernate/ejb3_examples.html
>>
>> gr. Martin
>>
>> Björn Sundin wrote:
>>> Hi,
>>>
>>> I have some problems getting in control of the id and version columns in
> my
>>> project. I need to have those attributes both in the ecore and in my
> model
>>> interface (non synthetic), in the EMF-Editor, however, they are not
> visible.
>>> I tried to set persistency annotations in the model interfaces with
> little
>>> success:
>>>
>>> FOR THE ID COLUMN:
>>> /**
>>> * @model id="true" required="true"
>>> * @generated
>>> */
>>> @Id @GeneratedValue(strategy=GenerationType.AUTO)
>>> int getId();
>>>
>>> /**
>>> * @generated
>>> */
>>> void setId(int value);
>>>
>>> RESULT: org.hibernate.id.IdentifierGenerationException: ids for this
> class
>>> must be manually assigned before calling save()
>>> (I notice that the generated PK `id` is auto_increment
> in
>>> MySql)
>>>
>>> FOR THE VERSION COLUMN:
>>> /**
>>> * @model required="true"
>>> * @generated
>>> */
>>> @Version
>>> int getVersion();
>>>
>>> /**
>>> * @generated
>>> */
>>> void setVersion(int value);
>>>
>>> RESULT: org.hibernate.MappingException: Duplicate property mapping of
>>> version found
>>>
>>> As I will have quite some tables in my model I'm not so keen in
> modifying
>>> all generated model interfaces in order to add any annotations. What I
>>> rather would like is to utilize the Teneo utility and so generate EMF -
>>> Hibernate OR mapping direct from the ecore file. In order to do that I
> have
>>> added
> persistenceProperties.setProperty(PersistenceOptions.USE_MAP PING_FILE,
>>> "true"); to the persistency property in the EditorPlugin. The generated
>>> hibernate.hbm.xml has anyway to be modified in the following way:
>>>
>>> GENERATED:
>>> <id name="id" type="int">
>>> <column not-null="true" unique="false" name="`id`"/>
>>> </id>
>>>
>>> MODIFIED:
>>> <id name="id" type="int" column="id" unsaved-value="0">
>>> <generator class="identity"/>
>>> </id>
>>>
>>> GENERATED:
>>> <version name="version" column="version"
>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>> ler">
>>> <meta attribute="syntheticVersion">true</meta>
>>> </version>
>>>
>>> MODIFIED:
>>> <version name="version" column="version"
>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>> ler"/>
>>>
>>> With the above modifications my EMF-Editor is working and I have no
> problems
>>> persisting the model objects to the database. Ids are generated and
> version
>>> is incremented.
>>>
>>> My question is if one somehow can override the mappings being generated
> in
>>> order to achieve above modified id- and version-elements?
>>>
>>> Thanks,
>>> Björn
>>>
>>> PS. Versions used and settings:
>>> - Eclipse IDE 3.2.1
>>> - EMF 2.2.2
>>> - Teneo 0.7.5 Maintenance Build
>>> - Hibernate 3.2
>>> - MySql and/or Derby embedded
>>> - Persistence properties set in the EditorPlugin:
>>>
>>> persistenceProperties.setProperty(PersistenceOptions.ID_COLU MN_NAME,
> "id");
>>>
> persistenceProperties.setProperty(PersistenceOptions.VERSION _COLUMN_NAME,
>>> "version");
>>>
>>>
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Possible to Override Generation of hibernate.hbm.xml? [message #73035 is a reply to message #73013] |
Wed, 28 February 2007 15:51 |
Eclipse User |
|
|
|
Originally posted by: bsu.bergauer.ch
Hi Martin,
Well the out-commented element is an artifact from my first try. Oddly
enough I think it was about how you meant it should look like :
<eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
instanceClassName="int">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@Id
@GeneratedValue(strategy="AUTO")"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
instanceClassName="int">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@Version"/>
</eAnnotations>
</eClassifiers>
It didn't work with the automatic mapping (and I think I missed out testing
it with the hibernate.hbm.xml) so I abandoned it and found other suggestions
in the newsgroup extending teneo.jpa to teneo.jpa/Id... :o/
After having reimplemented the eDataTypes, as above, both Id and Version
works well using the hibernate.hbm.xml! :) The automatic mapping, though,
still doesn't recognize the annotations:
hibernate.hbm.xml:
<class entity-name="StatusType" abstract="false" lazy="false"
discriminator-value="StatusType" table="`statustype`">
<meta attribute="eclassName">StatusType</meta>
<meta
attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
/meta>
<id name="id" type="int">
<column not-null="true" unique="false" name="`id`"/>
<generator class="native"/>
</id>
<discriminator column="`dtype`" type="string"/>
<version name="version" type="int">
<column not-null="true" unique="false" name="`version`"/>
</version>
<property name="name" lazy="false" insert="true" update="true"
not-null="true" unique="false" type="java.lang.String">
<column not-null="true" unique="false" name="`name`"/>
</property>
</class>
automatic mapping:
<class entity-name="StatusType" abstract="false" lazy="false"
discriminator-value="StatusType" table="`statustype`">
<meta attribute="eclassName">StatusType</meta>
<meta
attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
/meta>
<id name="id" type="int">
<column not-null="true" unique="false" name="`id`"/>
</id>
<discriminator column="`dtype`" type="string"/>
<property name="name" lazy="false" insert="true" update="true"
not-null="true" unique="false" type="java.lang.String">
<column not-null="true" unique="false" name="`name`"/>
</property>
<property name="version" lazy="false" insert="true" update="true"
not-null="true" unique="false" type="int">
<column not-null="true" unique="false" name="`version`"/>
</property>
</class>
Could it have to do with the version of Teneo that I use? I'm currently
using Teneo 0.7.5 Maintenance Build. I did download version 0.8.0 but had to
deactivate it as I'm using Eclipse 3.2.1.
Greetings,
Bj
|
|
|
Re: [Teneo] Possible to Override Generation of hibernate.hbm.xml? [message #73053 is a reply to message #73035] |
Wed, 28 February 2007 15:56 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Björn,
What could explain the difference is that after a change in the ecore (like adding an annotation)
you have to regenerate the java model code to get the change in ecore to the runtime layer.
For the automatic mapping the ecore model is not read from the ecore file but from the in-memory
ecore representation. This in-memory representation is created by the generated PackageImpl and can
be out of sync with the ecore file.
So can you try again (if you like) after regenerating the java model code?
gr. Martin
Björn Sundin wrote:
> Hi Martin,
>
> Well the out-commented element is an artifact from my first try. Oddly
> enough I think it was about how you meant it should look like :
>
> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
> instanceClassName="int">
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value="@Id
> @GeneratedValue(strategy="AUTO")"/>
> </eAnnotations>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
> instanceClassName="int">
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value="@Version"/>
> </eAnnotations>
> </eClassifiers>
>
> It didn't work with the automatic mapping (and I think I missed out testing
> it with the hibernate.hbm.xml) so I abandoned it and found other suggestions
> in the newsgroup extending teneo.jpa to teneo.jpa/Id... :o/
>
> After having reimplemented the eDataTypes, as above, both Id and Version
> works well using the hibernate.hbm.xml! :) The automatic mapping, though,
> still doesn't recognize the annotations:
>
> hibernate.hbm.xml:
>
> <class entity-name="StatusType" abstract="false" lazy="false"
> discriminator-value="StatusType" table="`statustype`">
> <meta attribute="eclassName">StatusType</meta>
> <meta
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
> /meta>
> <id name="id" type="int">
> <column not-null="true" unique="false" name="`id`"/>
> <generator class="native"/>
> </id>
> <discriminator column="`dtype`" type="string"/>
> <version name="version" type="int">
> <column not-null="true" unique="false" name="`version`"/>
> </version>
> <property name="name" lazy="false" insert="true" update="true"
> not-null="true" unique="false" type="java.lang.String">
> <column not-null="true" unique="false" name="`name`"/>
> </property>
> </class>
>
> automatic mapping:
>
> <class entity-name="StatusType" abstract="false" lazy="false"
> discriminator-value="StatusType" table="`statustype`">
> <meta attribute="eclassName">StatusType</meta>
> <meta
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
> /meta>
> <id name="id" type="int">
> <column not-null="true" unique="false" name="`id`"/>
> </id>
> <discriminator column="`dtype`" type="string"/>
> <property name="name" lazy="false" insert="true" update="true"
> not-null="true" unique="false" type="java.lang.String">
> <column not-null="true" unique="false" name="`name`"/>
> </property>
> <property name="version" lazy="false" insert="true" update="true"
> not-null="true" unique="false" type="int">
> <column not-null="true" unique="false" name="`version`"/>
> </property>
> </class>
>
> Could it have to do with the version of Teneo that I use? I'm currently
> using Teneo 0.7.5 Maintenance Build. I did download version 0.8.0 but had to
> deactivate it as I'm using Eclipse 3.2.1.
>
> Greetings,
> Björn
>
> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
> news:es42sn$jr2$1@utils.eclipse.org...
>> Hi Björn,
>> Afaics the <details...> tag in the eAnnotations of the AmsetVersion
> EDataType is commented out using
>> xml comment characters (<!-- and -->). Could that be a reason?
>>
>> Also the id annotation does not seem to be completely correct. The source
> should teneo.jpa and then
>> the value should also contain the @Id annotation.
>>
>> There should be no difference in generating the mapping file manually and
> then use that or the
>> automatic mapping in-memory (it also generates an in-memory mapping). I
> would suggest to use the
>> automatic in-memory mapping until you want to do extensive manual changes
> (for example to map to a
>> current db schema).
>>
>> gr. Martin
>>
>> Björn Sundin wrote:
>>> Hi Martin,
>>>
>>> Thanks for your reply. It definitely brought me on the right path and so
> I
>>> decided to define my own id and version datatypes in ecore:
>>>
>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
>>> instanceClassName="int">
>>> <eAnnotations source="teneo.jpa/Id">
>>> <details key="appinfo"
>>> value="@GeneratedValue(strategy="AUTO")"/ >
>>> </eAnnotations>
>>> </eClassifiers>
>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
>>> instanceClassName="int">
>>> <eAnnotations source="teneo.jpa/Version">
>>> <!-- <details key="appinfo" value="@Version"/> -->
>>> </eAnnotations>
>>> </eClassifiers>
>>>
>>> Those two datatypes are referenced in i.e StatusType:
>>>
>>> <eClassifiers xsi:type="ecore:EClass" name="StatusType">
>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
>>> lowerBound="1"
>>> eType="ecore:EDataType
>>> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
>>> lowerBound="1"
>>> eType="#//bergauer/rcp/amset/model/datatypes/AmsetId"
>>> iD="true"/>
>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="version"
>>> lowerBound="1"
>>> eType="#//bergauer/rcp/amset/model/datatypes/AmsetVersion"/ >
>>> </eClassifiers>
>>>
>>>
>>> I now have the following results:
>>>
>>> PersistenceOptions.USE_MAPPING_FILE set true:
>>> - The hibernate.hbm.xml I now have the id-element with generator,
>>> non-synthetic. Id is generated as expected
>>> - The version attribute that I define in ecore isn't recognized with
>>> annotation yet. In the hibernate.hbm.xml I have one version-element
> (with
>>> synthetic set true) and in the database I get two fields e_version and
>>> version. The PersistenceOptions.ALWAYS_VERSION is set false in the
>>> EditorPlugin.
>>>
>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>> discriminator-value="StatusType" table="`statustype`">
>>> <meta attribute="eclassName">StatusType</meta>
>>> <meta
>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>> /meta>
>>> <id name="id" type="int">
>>> <column not-null="true" unique="false" name="`id`"/>
>>> <generator class="native"/>
>>> </id>
>>> <discriminator column="`dtype`" type="string"/>
>>> <version name="e_version" column="e_version"
>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>> ler">
>>> <meta attribute="syntheticVersion">true</meta>
>>> </version>
>>> <property name="name" lazy="false" insert="true" update="true"
>>> not-null="true" unique="false" type="java.lang.String">
>>> <column not-null="true" unique="false" name="`name`"/>
>>> </property>
>>> </class>
>>>
>>> PersistenceOptions.USE_MAPPING_FILE set false:
>>> Neither id nor version work is reqognized. In the in-menory mapping
> I
>>> have no generator element for the id-element:
>>>
>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>> discriminator-value="StatusType" table="`statustype`">
>>> <meta attribute="eclassName">StatusType</meta>
>>> <meta
>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>> /meta>
>>> <id name="id" type="int">
>>> <column not-null="true" unique="false" name="`id`"/>
>>> </id>
>>> <discriminator column="`dtype`" type="string"/>
>>> <property name="name" lazy="false" insert="true" update="true"
>>> not-null="true" unique="false" type="java.lang.String">
>>> <column not-null="true" unique="false" name="`name`"/>
>>> </property>
>>> <property name="version" lazy="false" insert="true"
> update="true"
>>> not-null="true" unique="false" type="int">
>>> <column not-null="true" unique="false" name="`version`"/>
>>> </property>
>>> </class>
>>>
>>> The solution using the hibernate.hbm.xml seems to be the better way, so
> I
>>> think I will go on using PersistenceOptions.USE_MAPPING_FILE=true.
>>> Apperently I'm doing something wrong with the version though. Am I
>>> overlooking something obvious?
>>>
>>> cheers,
>>> Björn
>>>
>>> ref: [Teneo] Setting Id generator from ecore file
>>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>>> news:es1oej$v6h$1@utils.eclipse.org...
>>>> Hi Björn,
>>>> In Teneo annotations are not specified in the java code but in the
> model
>>> (ecore or xsd) or in a
>>>> separate xml.
>>>> So the @Id and @GeneratedValue(strategy=GenerationType.AUTO)
> annotations
>>> should be specified there.
>>>> If your id attributes all use an EDataType defined by yourselve then
> you
>>> can add the annotations to
>>>> the EDataType (so one place instead of at each attribute).
>>>>
>>>> See also here:
>>>> http://www.elver.org/hibernate/ejb3_format.html
>>>> http://www.elver.org/hibernate/ejb3_examples.html
>>>>
>>>> gr. Martin
>>>>
>>>> Björn Sundin wrote:
>>>>> Hi,
>>>>>
>>>>> I have some problems getting in control of the id and version columns
> in
>>> my
>>>>> project. I need to have those attributes both in the ecore and in my
>>> model
>>>>> interface (non synthetic), in the EMF-Editor, however, they are not
>>> visible.
>>>>> I tried to set persistency annotations in the model interfaces with
>>> little
>>>>> success:
>>>>>
>>>>> FOR THE ID COLUMN:
>>>>> /**
>>>>> * @model id="true" required="true"
>>>>> * @generated
>>>>> */
>>>>> @Id @GeneratedValue(strategy=GenerationType.AUTO)
>>>>> int getId();
>>>>>
>>>>> /**
>>>>> * @generated
>>>>> */
>>>>> void setId(int value);
>>>>>
>>>>> RESULT: org.hibernate.id.IdentifierGenerationException: ids for this
>>> class
>>>>> must be manually assigned before calling save()
>>>>> (I notice that the generated PK `id` is auto_increment
>>> in
>>>>> MySql)
>>>>>
>>>>> FOR THE VERSION COLUMN:
>>>>> /**
>>>>> * @model required="true"
>>>>> * @generated
>>>>> */
>>>>> @Version
>>>>> int getVersion();
>>>>>
>>>>> /**
>>>>> * @generated
>>>>> */
>>>>> void setVersion(int value);
>>>>>
>>>>> RESULT: org.hibernate.MappingException: Duplicate property mapping of
>>>>> version found
>>>>>
>>>>> As I will have quite some tables in my model I'm not so keen in
>>> modifying
>>>>> all generated model interfaces in order to add any annotations. What I
>>>>> rather would like is to utilize the Teneo utility and so generate
> EMF -
>>>>> Hibernate OR mapping direct from the ecore file. In order to do that I
>>> have
>>>>> added
>>> persistenceProperties.setProperty(PersistenceOptions.USE_MAP PING_FILE,
>>>>> "true"); to the persistency property in the EditorPlugin. The
> generated
>>>>> hibernate.hbm.xml has anyway to be modified in the following way:
>>>>>
>>>>> GENERATED:
>>>>> <id name="id" type="int">
>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>> </id>
>>>>>
>>>>> MODIFIED:
>>>>> <id name="id" type="int" column="id" unsaved-value="0">
>>>>> <generator class="identity"/>
>>>>> </id>
>>>>>
>>>>> GENERATED:
>>>>> <version name="version" column="version"
>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>> ler">
>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>> </version>
>>>>>
>>>>> MODIFIED:
>>>>> <version name="version" column="version"
>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>> ler"/>
>>>>>
>>>>> With the above modifications my EMF-Editor is working and I have no
>>> problems
>>>>> persisting the model objects to the database. Ids are generated and
>>> version
>>>>> is incremented.
>>>>>
>>>>> My question is if one somehow can override the mappings being
> generated
>>> in
>>>>> order to achieve above modified id- and version-elements?
>>>>>
>>>>> Thanks,
>>>>> Björn
>>>>>
>>>>> PS. Versions used and settings:
>>>>> - Eclipse IDE 3.2.1
>>>>> - EMF 2.2.2
>>>>> - Teneo 0.7.5 Maintenance Build
>>>>> - Hibernate 3.2
>>>>> - MySql and/or Derby embedded
>>>>> - Persistence properties set in the EditorPlugin:
>>>>>
>>>>> persistenceProperties.setProperty(PersistenceOptions.ID_COLU MN_NAME,
>>> "id");
> persistenceProperties.setProperty(PersistenceOptions.VERSION _COLUMN_NAME,
>>>>> "version");
>>>>>
>>>>>
>>>>>
>>>> --
>>>>
>>>> With Regards, Martin Taal
>>>>
>>>> Springsite/Elver.org
>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>> The Netherlands
>>>> 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
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Possible to Override Generation of hibernate.hbm.xml? [message #73075 is a reply to message #73053] |
Wed, 28 February 2007 16:16 |
Eclipse User |
|
|
|
Originally posted by: bsu.bergauer.ch
Hi Martin,
I use to regenerate all code (model, edit, editor) every time I make a
change to the ecore model. Now I even deleted the model code and generated
it from scratch. I'm sorry to say that it still is a problem with the
autogenerated mapping. It's exactly the same as in my prevoious post.
Could it be a problem that the eDataTypes are in another package than the
model code?
Greetings,
Bj
|
|
| |
Re: [Teneo] Possible to Override Generation of hibernate.hbm.xml? [message #73116 is a reply to message #73096] |
Wed, 28 February 2007 17:05 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
No problem. Actually, I am not sure why you would need to move the edatatype to the same package.
When you said regenerate, did you regenerate the model code of both epackages?
gr. Martin
Björn Sundin wrote:
> I just moved the eDataTypes to the same package as the model code and the
> autogenerated mapping works! I guess I'm lucky not sitting in your office
> right now...
>
> Greetings,
> Björn
>
>
> "Björn Sundin" <bsu@bergauer.ch> schrieb im Newsbeitrag
> news:es49s3$403$1@utils.eclipse.org...
>> Hi Martin,
>>
>> I use to regenerate all code (model, edit, editor) every time I make a
>> change to the ecore model. Now I even deleted the model code and generated
>> it from scratch. I'm sorry to say that it still is a problem with the
>> autogenerated mapping. It's exactly the same as in my prevoious post.
>> Could it be a problem that the eDataTypes are in another package than the
>> model code?
>>
>> Greetings,
>> Björn
>>
>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>> news:es48o3$ak$1@utils.eclipse.org...
>>> Hi Björn,
>>> What could explain the difference is that after a change in the ecore
>> (like adding an annotation)
>>> you have to regenerate the java model code to get the change in ecore to
>> the runtime layer.
>>> For the automatic mapping the ecore model is not read from the ecore
> file
>> but from the in-memory
>>> ecore representation. This in-memory representation is created by the
>> generated PackageImpl and can
>>> be out of sync with the ecore file.
>>> So can you try again (if you like) after regenerating the java model
> code?
>>> gr. Martin
>>>
>>> Björn Sundin wrote:
>>>> Hi Martin,
>>>>
>>>> Well the out-commented element is an artifact from my first try. Oddly
>>>> enough I think it was about how you meant it should look like :
>>>>
>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
>>>> instanceClassName="int">
>>>> <eAnnotations source="teneo.jpa">
>>>> <details key="appinfo" value="@Id
>>>> @GeneratedValue(strategy="AUTO")"/>
>>>> </eAnnotations>
>>>> </eClassifiers>
>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
>>>> instanceClassName="int">
>>>> <eAnnotations source="teneo.jpa">
>>>> <details key="appinfo" value="@Version"/>
>>>> </eAnnotations>
>>>> </eClassifiers>
>>>>
>>>> It didn't work with the automatic mapping (and I think I missed out
>> testing
>>>> it with the hibernate.hbm.xml) so I abandoned it and found other
>> suggestions
>>>> in the newsgroup extending teneo.jpa to teneo.jpa/Id... :o/
>>>>
>>>> After having reimplemented the eDataTypes, as above, both Id and
> Version
>>>> works well using the hibernate.hbm.xml! :) The automatic mapping,
>> though,
>>>> still doesn't recognize the annotations:
>>>>
>>>> hibernate.hbm.xml:
>>>>
>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>> discriminator-value="StatusType" table="`statustype`">
>>>> <meta attribute="eclassName">StatusType</meta>
>>>> <meta
>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>> /meta>
>>>> <id name="id" type="int">
>>>> <column not-null="true" unique="false" name="`id`"/>
>>>> <generator class="native"/>
>>>> </id>
>>>> <discriminator column="`dtype`" type="string"/>
>>>> <version name="version" type="int">
>>>> <column not-null="true" unique="false" name="`version`"/>
>>>> </version>
>>>> <property name="name" lazy="false" insert="true" update="true"
>>>> not-null="true" unique="false" type="java.lang.String">
>>>> <column not-null="true" unique="false" name="`name`"/>
>>>> </property>
>>>> </class>
>>>>
>>>> automatic mapping:
>>>>
>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>> discriminator-value="StatusType" table="`statustype`">
>>>> <meta attribute="eclassName">StatusType</meta>
>>>> <meta
>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>> /meta>
>>>> <id name="id" type="int">
>>>> <column not-null="true" unique="false" name="`id`"/>
>>>> </id>
>>>> <discriminator column="`dtype`" type="string"/>
>>>> <property name="name" lazy="false" insert="true" update="true"
>>>> not-null="true" unique="false" type="java.lang.String">
>>>> <column not-null="true" unique="false" name="`name`"/>
>>>> </property>
>>>> <property name="version" lazy="false" insert="true"
>> update="true"
>>>> not-null="true" unique="false" type="int">
>>>> <column not-null="true" unique="false" name="`version`"/>
>>>> </property>
>>>> </class>
>>>>
>>>> Could it have to do with the version of Teneo that I use? I'm
> currently
>>>> using Teneo 0.7.5 Maintenance Build. I did download version 0.8.0 but
>> had to
>>>> deactivate it as I'm using Eclipse 3.2.1.
>>>>
>>>> Greetings,
>>>> Björn
>>>>
>>>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>>>> news:es42sn$jr2$1@utils.eclipse.org...
>>>>> Hi Björn,
>>>>> Afaics the <details...> tag in the eAnnotations of the AmsetVersion
>>>> EDataType is commented out using
>>>>> xml comment characters (<!-- and -->). Could that be a reason?
>>>>>
>>>>> Also the id annotation does not seem to be completely correct. The
>> source
>>>> should teneo.jpa and then
>>>>> the value should also contain the @Id annotation.
>>>>>
>>>>> There should be no difference in generating the mapping file manually
>> and
>>>> then use that or the
>>>>> automatic mapping in-memory (it also generates an in-memory mapping).
> I
>>>> would suggest to use the
>>>>> automatic in-memory mapping until you want to do extensive manual
>> changes
>>>> (for example to map to a
>>>>> current db schema).
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> Björn Sundin wrote:
>>>>>> Hi Martin,
>>>>>>
>>>>>> Thanks for your reply. It definitely brought me on the right path
> and
>> so
>>>> I
>>>>>> decided to define my own id and version datatypes in ecore:
>>>>>>
>>>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
>>>>>> instanceClassName="int">
>>>>>> <eAnnotations source="teneo.jpa/Id">
>>>>>> <details key="appinfo"
>>>>>> value="@GeneratedValue(strategy="AUTO")"/ >
>>>>>> </eAnnotations>
>>>>>> </eClassifiers>
>>>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
>>>>>> instanceClassName="int">
>>>>>> <eAnnotations source="teneo.jpa/Version">
>>>>>> <!-- <details key="appinfo" value="@Version"/> -->
>>>>>> </eAnnotations>
>>>>>> </eClassifiers>
>>>>>>
>>>>>> Those two datatypes are referenced in i.e StatusType:
>>>>>>
>>>>>> <eClassifiers xsi:type="ecore:EClass" name="StatusType">
>>>>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
>>>>>> lowerBound="1"
>>>>>> eType="ecore:EDataType
>>>>>> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
>>>>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
>>>>>> lowerBound="1"
>>>>>> eType="#//bergauer/rcp/amset/model/datatypes/AmsetId"
>>>>>> iD="true"/>
>>>>>> <eStructuralFeatures xsi:type="ecore:EAttribute"
>> name="version"
>>>>>> lowerBound="1"
>>>>>>
>> eType="#//bergauer/rcp/amset/model/datatypes/AmsetVersion"/ >
>>>>>> </eClassifiers>
>>>>>>
>>>>>>
>>>>>> I now have the following results:
>>>>>>
>>>>>> PersistenceOptions.USE_MAPPING_FILE set true:
>>>>>> - The hibernate.hbm.xml I now have the id-element with
> generator,
>>>>>> non-synthetic. Id is generated as expected
>>>>>> - The version attribute that I define in ecore isn't recognized
>> with
>>>>>> annotation yet. In the hibernate.hbm.xml I have one version-element
>>>> (with
>>>>>> synthetic set true) and in the database I get two fields e_version
> and
>>>>>> version. The PersistenceOptions.ALWAYS_VERSION is set false in the
>>>>>> EditorPlugin.
>>>>>>
>>>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>>>> discriminator-value="StatusType" table="`statustype`">
>>>>>> <meta attribute="eclassName">StatusType</meta>
>>>>>> <meta
>>>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>>>> /meta>
>>>>>> <id name="id" type="int">
>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>> <generator class="native"/>
>>>>>> </id>
>>>>>> <discriminator column="`dtype`" type="string"/>
>>>>>> <version name="e_version" column="e_version"
>>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>>> ler">
>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>> </version>
>>>>>> <property name="name" lazy="false" insert="true"
> update="true"
>>>>>> not-null="true" unique="false" type="java.lang.String">
>>>>>> <column not-null="true" unique="false" name="`name`"/>
>>>>>> </property>
>>>>>> </class>
>>>>>>
>>>>>> PersistenceOptions.USE_MAPPING_FILE set false:
>>>>>> Neither id nor version work is reqognized. In the in-menory
>> mapping
>>>> I
>>>>>> have no generator element for the id-element:
>>>>>>
>>>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>>>> discriminator-value="StatusType" table="`statustype`">
>>>>>> <meta attribute="eclassName">StatusType</meta>
>>>>>> <meta
>>>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>>>> /meta>
>>>>>> <id name="id" type="int">
>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>> </id>
>>>>>> <discriminator column="`dtype`" type="string"/>
>>>>>> <property name="name" lazy="false" insert="true"
> update="true"
>>>>>> not-null="true" unique="false" type="java.lang.String">
>>>>>> <column not-null="true" unique="false" name="`name`"/>
>>>>>> </property>
>>>>>> <property name="version" lazy="false" insert="true"
>>>> update="true"
>>>>>> not-null="true" unique="false" type="int">
>>>>>> <column not-null="true" unique="false"
> name="`version`"/>
>>>>>> </property>
>>>>>> </class>
>>>>>>
>>>>>> The solution using the hibernate.hbm.xml seems to be the better way,
>> so
>>>> I
>>>>>> think I will go on using PersistenceOptions.USE_MAPPING_FILE=true.
>>>>>> Apperently I'm doing something wrong with the version though. Am I
>>>>>> overlooking something obvious?
>>>>>>
>>>>>> cheers,
>>>>>> Björn
>>>>>>
>>>>>> ref: [Teneo] Setting Id generator from ecore file
>>>>>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>>>>>> news:es1oej$v6h$1@utils.eclipse.org...
>>>>>>> Hi Björn,
>>>>>>> In Teneo annotations are not specified in the java code but in the
>>>> model
>>>>>> (ecore or xsd) or in a
>>>>>>> separate xml.
>>>>>>> So the @Id and @GeneratedValue(strategy=GenerationType.AUTO)
>>>> annotations
>>>>>> should be specified there.
>>>>>>> If your id attributes all use an EDataType defined by yourselve
> then
>>>> you
>>>>>> can add the annotations to
>>>>>>> the EDataType (so one place instead of at each attribute).
>>>>>>>
>>>>>>> See also here:
>>>>>>> http://www.elver.org/hibernate/ejb3_format.html
>>>>>>> http://www.elver.org/hibernate/ejb3_examples.html
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> Björn Sundin wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I have some problems getting in control of the id and version
>> columns
>>>> in
>>>>>> my
>>>>>>>> project. I need to have those attributes both in the ecore and in
> my
>>>>>> model
>>>>>>>> interface (non synthetic), in the EMF-Editor, however, they are
> not
>>>>>> visible.
>>>>>>>> I tried to set persistency annotations in the model interfaces
> with
>>>>>> little
>>>>>>>> success:
>>>>>>>>
>>>>>>>> FOR THE ID COLUMN:
>>>>>>>> /**
>>>>>>>> * @model id="true" required="true"
>>>>>>>> * @generated
>>>>>>>> */
>>>>>>>> @Id @GeneratedValue(strategy=GenerationType.AUTO)
>>>>>>>> int getId();
>>>>>>>>
>>>>>>>> /**
>>>>>>>> * @generated
>>>>>>>> */
>>>>>>>> void setId(int value);
>>>>>>>>
>>>>>>>> RESULT: org.hibernate.id.IdentifierGenerationException: ids for
> this
>>>>>> class
>>>>>>>> must be manually assigned before calling save()
>>>>>>>> (I notice that the generated PK `id` is
>> auto_increment
>>>>>> in
>>>>>>>> MySql)
>>>>>>>>
>>>>>>>> FOR THE VERSION COLUMN:
>>>>>>>> /**
>>>>>>>> * @model required="true"
>>>>>>>> * @generated
>>>>>>>> */
>>>>>>>> @Version
>>>>>>>> int getVersion();
>>>>>>>>
>>>>>>>> /**
>>>>>>>> * @generated
>>>>>>>> */
>>>>>>>> void setVersion(int value);
>>>>>>>>
>>>>>>>> RESULT: org.hibernate.MappingException: Duplicate property mapping
>> of
>>>>>>>> version found
>>>>>>>>
>>>>>>>> As I will have quite some tables in my model I'm not so keen in
>>>>>> modifying
>>>>>>>> all generated model interfaces in order to add any annotations.
> What
>> I
>>>>>>>> rather would like is to utilize the Teneo utility and so generate
>>>> EMF -
>>>>>>>> Hibernate OR mapping direct from the ecore file. In order to do
> that
>> I
>>>>>> have
>>>>>>>> added
> persistenceProperties.setProperty(PersistenceOptions.USE_MAP PING_FILE,
>>>>>>>> "true"); to the persistency property in the EditorPlugin. The
>>>> generated
>>>>>>>> hibernate.hbm.xml has anyway to be modified in the following way:
>>>>>>>>
>>>>>>>> GENERATED:
>>>>>>>> <id name="id" type="int">
>>>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>>>> </id>
>>>>>>>>
>>>>>>>> MODIFIED:
>>>>>>>> <id name="id" type="int" column="id" unsaved-value="0">
>>>>>>>> <generator class="identity"/>
>>>>>>>> </id>
>>>>>>>>
>>>>>>>> GENERATED:
>>>>>>>> <version name="version" column="version"
>>>>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>>>>> ler">
>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>> </version>
>>>>>>>>
>>>>>>>> MODIFIED:
>>>>>>>> <version name="version" column="version"
>>>>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>>>>> ler"/>
>>>>>>>>
>>>>>>>> With the above modifications my EMF-Editor is working and I have
> no
>>>>>> problems
>>>>>>>> persisting the model objects to the database. Ids are generated
> and
>>>>>> version
>>>>>>>> is incremented.
>>>>>>>>
>>>>>>>> My question is if one somehow can override the mappings being
>>>> generated
>>>>>> in
>>>>>>>> order to achieve above modified id- and version-elements?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Björn
>>>>>>>>
>>>>>>>> PS. Versions used and settings:
>>>>>>>> - Eclipse IDE 3.2.1
>>>>>>>> - EMF 2.2.2
>>>>>>>> - Teneo 0.7.5 Maintenance Build
>>>>>>>> - Hibernate 3.2
>>>>>>>> - MySql and/or Derby embedded
>>>>>>>> - Persistence properties set in the EditorPlugin:
>>>>>>>>
>>>>>>>>
> persistenceProperties.setProperty(PersistenceOptions.ID_COLU MN_NAME,
>>>>>> "id");
>> persistenceProperties.setProperty(PersistenceOptions.VERSION _COLUMN_NAME,
>>>>>>>> "version");
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>> --
>>>>>>>
>>>>>>> With Regards, Martin Taal
>>>>>>>
>>>>>>> Springsite/Elver.org
>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>> The Netherlands
>>>>>>> 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
>>>>> --
>>>>>
>>>>> With Regards, Martin Taal
>>>>>
>>>>> Springsite/Elver.org
>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>> The Netherlands
>>>>> 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
>>>>
>>>
>>> --
>>>
>>> With Regards, Martin Taal
>>>
>>> Springsite/Elver.org
>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>> The Netherlands
>>> 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
>>
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Possible to Override Generation of hibernate.hbm.xml? [message #73169 is a reply to message #73116] |
Wed, 28 February 2007 17:21 |
Eclipse User |
|
|
|
Originally posted by: bsu.bergauer.ch
Yes, I beleve I do... Both packages are in same ecore model and thus I have
only one genmodel. When I regenerate the model code both packages are
created. What I noticed is that the Factory and Package classes where the
model code is located gets the prefix of the package direct above. This is
not the case for the Factory and Package classes where only the eDataTypes
are located. Here the generated files are named without prefix
(Factory.java, Package.java resp. in impl FactoryImpl.java,
PackageImpl.java ). In FactoryImpl.java I also get a duplicated method
getPackage() (though static and marked @deprecated) every time I regenerate.
Greetings,
Bj
|
|
|
Re: [Teneo] Possible to Override Generation of hibernate.hbm.xml? [message #73242 is a reply to message #73169] |
Wed, 28 February 2007 19:27 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Okay, to be honest I do not know exactly if something is out-of-the-ordinary here. Maybe, Ed, do you
know?
gr. Martin
Björn Sundin wrote:
> Yes, I beleve I do... Both packages are in same ecore model and thus I have
> only one genmodel. When I regenerate the model code both packages are
> created. What I noticed is that the Factory and Package classes where the
> model code is located gets the prefix of the package direct above. This is
> not the case for the Factory and Package classes where only the eDataTypes
> are located. Here the generated files are named without prefix
> (Factory.java, Package.java resp. in impl FactoryImpl.java,
> PackageImpl.java ). In FactoryImpl.java I also get a duplicated method
> getPackage() (though static and marked @deprecated) every time I regenerate.
>
> Greetings,
> Björn
>
>
> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
> news:es4cpk$8vf$1@utils.eclipse.org...
>> No problem. Actually, I am not sure why you would need to move the
> edatatype to the same package.
>> When you said regenerate, did you regenerate the model code of both
> epackages?
>> gr. Martin
>>
>> Björn Sundin wrote:
>>> I just moved the eDataTypes to the same package as the model code and
> the
>>> autogenerated mapping works! I guess I'm lucky not sitting in your
> office
>>> right now...
>>>
>>> Greetings,
>>> Björn
>>>
>>>
>>> "Björn Sundin" <bsu@bergauer.ch> schrieb im Newsbeitrag
>>> news:es49s3$403$1@utils.eclipse.org...
>>>> Hi Martin,
>>>>
>>>> I use to regenerate all code (model, edit, editor) every time I make a
>>>> change to the ecore model. Now I even deleted the model code and
> generated
>>>> it from scratch. I'm sorry to say that it still is a problem with the
>>>> autogenerated mapping. It's exactly the same as in my prevoious post.
>>>> Could it be a problem that the eDataTypes are in another package than
> the
>>>> model code?
>>>>
>>>> Greetings,
>>>> Björn
>>>>
>>>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>>>> news:es48o3$ak$1@utils.eclipse.org...
>>>>> Hi Björn,
>>>>> What could explain the difference is that after a change in the ecore
>>>> (like adding an annotation)
>>>>> you have to regenerate the java model code to get the change in ecore
> to
>>>> the runtime layer.
>>>>> For the automatic mapping the ecore model is not read from the ecore
>>> file
>>>> but from the in-memory
>>>>> ecore representation. This in-memory representation is created by the
>>>> generated PackageImpl and can
>>>>> be out of sync with the ecore file.
>>>>> So can you try again (if you like) after regenerating the java model
>>> code?
>>>>> gr. Martin
>>>>>
>>>>> Björn Sundin wrote:
>>>>>> Hi Martin,
>>>>>>
>>>>>> Well the out-commented element is an artifact from my first try.
> Oddly
>>>>>> enough I think it was about how you meant it should look like :
>>>>>>
>>>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
>>>>>> instanceClassName="int">
>>>>>> <eAnnotations source="teneo.jpa">
>>>>>> <details key="appinfo" value="@Id
>>>>>> @GeneratedValue(strategy="AUTO")"/>
>>>>>> </eAnnotations>
>>>>>> </eClassifiers>
>>>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
>>>>>> instanceClassName="int">
>>>>>> <eAnnotations source="teneo.jpa">
>>>>>> <details key="appinfo" value="@Version"/>
>>>>>> </eAnnotations>
>>>>>> </eClassifiers>
>>>>>>
>>>>>> It didn't work with the automatic mapping (and I think I missed out
>>>> testing
>>>>>> it with the hibernate.hbm.xml) so I abandoned it and found other
>>>> suggestions
>>>>>> in the newsgroup extending teneo.jpa to teneo.jpa/Id... :o/
>>>>>>
>>>>>> After having reimplemented the eDataTypes, as above, both Id and
>>> Version
>>>>>> works well using the hibernate.hbm.xml! :) The automatic mapping,
>>>> though,
>>>>>> still doesn't recognize the annotations:
>>>>>>
>>>>>> hibernate.hbm.xml:
>>>>>>
>>>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>>>> discriminator-value="StatusType" table="`statustype`">
>>>>>> <meta attribute="eclassName">StatusType</meta>
>>>>>> <meta
>>>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>>>> /meta>
>>>>>> <id name="id" type="int">
>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>> <generator class="native"/>
>>>>>> </id>
>>>>>> <discriminator column="`dtype`" type="string"/>
>>>>>> <version name="version" type="int">
>>>>>> <column not-null="true" unique="false" name="`version`"/>
>>>>>> </version>
>>>>>> <property name="name" lazy="false" insert="true"
> update="true"
>>>>>> not-null="true" unique="false" type="java.lang.String">
>>>>>> <column not-null="true" unique="false" name="`name`"/>
>>>>>> </property>
>>>>>> </class>
>>>>>>
>>>>>> automatic mapping:
>>>>>>
>>>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>>>> discriminator-value="StatusType" table="`statustype`">
>>>>>> <meta attribute="eclassName">StatusType</meta>
>>>>>> <meta
>>>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>>>> /meta>
>>>>>> <id name="id" type="int">
>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>> </id>
>>>>>> <discriminator column="`dtype`" type="string"/>
>>>>>> <property name="name" lazy="false" insert="true"
> update="true"
>>>>>> not-null="true" unique="false" type="java.lang.String">
>>>>>> <column not-null="true" unique="false" name="`name`"/>
>>>>>> </property>
>>>>>> <property name="version" lazy="false" insert="true"
>>>> update="true"
>>>>>> not-null="true" unique="false" type="int">
>>>>>> <column not-null="true" unique="false" name="`version`"/>
>>>>>> </property>
>>>>>> </class>
>>>>>>
>>>>>> Could it have to do with the version of Teneo that I use? I'm
>>> currently
>>>>>> using Teneo 0.7.5 Maintenance Build. I did download version 0.8.0 but
>>>> had to
>>>>>> deactivate it as I'm using Eclipse 3.2.1.
>>>>>>
>>>>>> Greetings,
>>>>>> Björn
>>>>>>
>>>>>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>>>>>> news:es42sn$jr2$1@utils.eclipse.org...
>>>>>>> Hi Björn,
>>>>>>> Afaics the <details...> tag in the eAnnotations of the AmsetVersion
>>>>>> EDataType is commented out using
>>>>>>> xml comment characters (<!-- and -->). Could that be a reason?
>>>>>>>
>>>>>>> Also the id annotation does not seem to be completely correct. The
>>>> source
>>>>>> should teneo.jpa and then
>>>>>>> the value should also contain the @Id annotation.
>>>>>>>
>>>>>>> There should be no difference in generating the mapping file
> manually
>>>> and
>>>>>> then use that or the
>>>>>>> automatic mapping in-memory (it also generates an in-memory
> mapping).
>>> I
>>>>>> would suggest to use the
>>>>>>> automatic in-memory mapping until you want to do extensive manual
>>>> changes
>>>>>> (for example to map to a
>>>>>>> current db schema).
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> Björn Sundin wrote:
>>>>>>>> Hi Martin,
>>>>>>>>
>>>>>>>> Thanks for your reply. It definitely brought me on the right path
>>> and
>>>> so
>>>>>> I
>>>>>>>> decided to define my own id and version datatypes in ecore:
>>>>>>>>
>>>>>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
>>>>>>>> instanceClassName="int">
>>>>>>>> <eAnnotations source="teneo.jpa/Id">
>>>>>>>> <details key="appinfo"
>>>>>>>> value="@GeneratedValue(strategy="AUTO")"/ >
>>>>>>>> </eAnnotations>
>>>>>>>> </eClassifiers>
>>>>>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
>>>>>>>> instanceClassName="int">
>>>>>>>> <eAnnotations source="teneo.jpa/Version">
>>>>>>>> <!-- <details key="appinfo" value="@Version"/> -->
>>>>>>>> </eAnnotations>
>>>>>>>> </eClassifiers>
>>>>>>>>
>>>>>>>> Those two datatypes are referenced in i.e StatusType:
>>>>>>>>
>>>>>>>> <eClassifiers xsi:type="ecore:EClass" name="StatusType">
>>>>>>>> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="name"
>>>>>>>> lowerBound="1"
>>>>>>>> eType="ecore:EDataType
>>>>>>>> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
>>>>>>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
>>>>>>>> lowerBound="1"
>>>>>>>> eType="#//bergauer/rcp/amset/model/datatypes/AmsetId"
>>>>>>>> iD="true"/>
>>>>>>>> <eStructuralFeatures xsi:type="ecore:EAttribute"
>>>> name="version"
>>>>>>>> lowerBound="1"
>>>>>>>>
>>>> eType="#//bergauer/rcp/amset/model/datatypes/AmsetVersion"/ >
>>>>>>>> </eClassifiers>
>>>>>>>>
>>>>>>>>
>>>>>>>> I now have the following results:
>>>>>>>>
>>>>>>>> PersistenceOptions.USE_MAPPING_FILE set true:
>>>>>>>> - The hibernate.hbm.xml I now have the id-element with
>>> generator,
>>>>>>>> non-synthetic. Id is generated as expected
>>>>>>>> - The version attribute that I define in ecore isn't recognized
>>>> with
>>>>>>>> annotation yet. In the hibernate.hbm.xml I have one version-element
>>>>>> (with
>>>>>>>> synthetic set true) and in the database I get two fields e_version
>>> and
>>>>>>>> version. The PersistenceOptions.ALWAYS_VERSION is set false in the
>>>>>>>> EditorPlugin.
>>>>>>>>
>>>>>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>>>>>> discriminator-value="StatusType" table="`statustype`">
>>>>>>>> <meta attribute="eclassName">StatusType</meta>
>>>>>>>> <meta
>>>>>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>>>>>> /meta>
>>>>>>>> <id name="id" type="int">
>>>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>>>> <generator class="native"/>
>>>>>>>> </id>
>>>>>>>> <discriminator column="`dtype`" type="string"/>
>>>>>>>> <version name="e_version" column="e_version"
>>>>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>>>>> ler">
>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>> </version>
>>>>>>>> <property name="name" lazy="false" insert="true"
>>> update="true"
>>>>>>>> not-null="true" unique="false" type="java.lang.String">
>>>>>>>> <column not-null="true" unique="false" name="`name`"/>
>>>>>>>> </property>
>>>>>>>> </class>
>>>>>>>>
>>>>>>>> PersistenceOptions.USE_MAPPING_FILE set false:
>>>>>>>> Neither id nor version work is reqognized. In the in-menory
>>>> mapping
>>>>>> I
>>>>>>>> have no generator element for the id-element:
>>>>>>>>
>>>>>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>>>>>> discriminator-value="StatusType" table="`statustype`">
>>>>>>>> <meta attribute="eclassName">StatusType</meta>
>>>>>>>> <meta
>>>>>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>>>>>> /meta>
>>>>>>>> <id name="id" type="int">
>>>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>>>> </id>
>>>>>>>> <discriminator column="`dtype`" type="string"/>
>>>>>>>> <property name="name" lazy="false" insert="true"
>>> update="true"
>>>>>>>> not-null="true" unique="false" type="java.lang.String">
>>>>>>>> <column not-null="true" unique="false" name="`name`"/>
>>>>>>>> </property>
>>>>>>>> <property name="version" lazy="false" insert="true"
>>>>>> update="true"
>>>>>>>> not-null="true" unique="false" type="int">
>>>>>>>> <column not-null="true" unique="false"
>>> name="`version`"/>
>>>>>>>> </property>
>>>>>>>> </class>
>>>>>>>>
>>>>>>>> The solution using the hibernate.hbm.xml seems to be the better
> way,
>>>> so
>>>>>> I
>>>>>>>> think I will go on using PersistenceOptions.USE_MAPPING_FILE=true.
>>>>>>>> Apperently I'm doing something wrong with the version though. Am I
>>>>>>>> overlooking something obvious?
>>>>>>>>
>>>>>>>> cheers,
>>>>>>>> Björn
>>>>>>>>
>>>>>>>> ref: [Teneo] Setting Id generator from ecore file
>>>>>>>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>>>>>>>> news:es1oej$v6h$1@utils.eclipse.org...
>>>>>>>>> Hi Björn,
>>>>>>>>> In Teneo annotations are not specified in the java code but in the
>>>>>> model
>>>>>>>> (ecore or xsd) or in a
>>>>>>>>> separate xml.
>>>>>>>>> So the @Id and @GeneratedValue(strategy=GenerationType.AUTO)
>>>>>> annotations
>>>>>>>> should be specified there.
>>>>>>>>> If your id attributes all use an EDataType defined by yourselve
>>> then
>>>>>> you
>>>>>>>> can add the annotations to
>>>>>>>>> the EDataType (so one place instead of at each attribute).
>>>>>>>>>
>>>>>>>>> See also here:
>>>>>>>>> http://www.elver.org/hibernate/ejb3_format.html
>>>>>>>>> http://www.elver.org/hibernate/ejb3_examples.html
>>>>>>>>>
>>>>>>>>> gr. Martin
>>>>>>>>>
>>>>>>>>> Björn Sundin wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I have some problems getting in control of the id and version
>>>> columns
>>>>>> in
>>>>>>>> my
>>>>>>>>>> project. I need to have those attributes both in the ecore and in
>>> my
>>>>>>>> model
>>>>>>>>>> interface (non synthetic), in the EMF-Editor, however, they are
>>> not
>>>>>>>> visible.
>>>>>>>>>> I tried to set persistency annotations in the model interfaces
>>> with
>>>>>>>> little
>>>>>>>>>> success:
>>>>>>>>>>
>>>>>>>>>> FOR THE ID COLUMN:
>>>>>>>>>> /**
>>>>>>>>>> * @model id="true" required="true"
>>>>>>>>>> * @generated
>>>>>>>>>> */
>>>>>>>>>> @Id @GeneratedValue(strategy=GenerationType.AUTO)
>>>>>>>>>> int getId();
>>>>>>>>>>
>>>>>>>>>> /**
>>>>>>>>>> * @generated
>>>>>>>>>> */
>>>>>>>>>> void setId(int value);
>>>>>>>>>>
>>>>>>>>>> RESULT: org.hibernate.id.IdentifierGenerationException: ids for
>>> this
>>>>>>>> class
>>>>>>>>>> must be manually assigned before calling save()
>>>>>>>>>> (I notice that the generated PK `id` is
>>>> auto_increment
>>>>>>>> in
>>>>>>>>>> MySql)
>>>>>>>>>>
>>>>>>>>>> FOR THE VERSION COLUMN:
>>>>>>>>>> /**
>>>>>>>>>> * @model required="true"
>>>>>>>>>> * @generated
>>>>>>>>>> */
>>>>>>>>>> @Version
>>>>>>>>>> int getVersion();
>>>>>>>>>>
>>>>>>>>>> /**
>>>>>>>>>> * @generated
>>>>>>>>>> */
>>>>>>>>>> void setVersion(int value);
>>>>>>>>>>
>>>>>>>>>> RESULT: org.hibernate.MappingException: Duplicate property
> mapping
>>>> of
>>>>>>>>>> version found
>>>>>>>>>>
>>>>>>>>>> As I will have quite some tables in my model I'm not so keen in
>>>>>>>> modifying
>>>>>>>>>> all generated model interfaces in order to add any annotations.
>>> What
>>>> I
>>>>>>>>>> rather would like is to utilize the Teneo utility and so generate
>>>>>> EMF -
>>>>>>>>>> Hibernate OR mapping direct from the ecore file. In order to do
>>> that
>>>> I
>>>>>>>> have
>>>>>>>>>> added
>>> persistenceProperties.setProperty(PersistenceOptions.USE_MAP PING_FILE,
>>>>>>>>>> "true"); to the persistency property in the EditorPlugin. The
>>>>>> generated
>>>>>>>>>> hibernate.hbm.xml has anyway to be modified in the following way:
>>>>>>>>>>
>>>>>>>>>> GENERATED:
>>>>>>>>>> <id name="id" type="int">
>>>>>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>>>>>> </id>
>>>>>>>>>>
>>>>>>>>>> MODIFIED:
>>>>>>>>>> <id name="id" type="int" column="id" unsaved-value="0">
>>>>>>>>>> <generator class="identity"/>
>>>>>>>>>> </id>
>>>>>>>>>>
>>>>>>>>>> GENERATED:
>>>>>>>>>> <version name="version" column="version"
>>>>>>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>>>>>>> ler">
>>>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>>>> </version>
>>>>>>>>>>
>>>>>>>>>> MODIFIED:
>>>>>>>>>> <version name="version" column="version"
>>>>>>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>>>>>>> ler"/>
>>>>>>>>>>
>>>>>>>>>> With the above modifications my EMF-Editor is working and I have
>>> no
>>>>>>>> problems
>>>>>>>>>> persisting the model objects to the database. Ids are generated
>>> and
>>>>>>>> version
>>>>>>>>>> is incremented.
>>>>>>>>>>
>>>>>>>>>> My question is if one somehow can override the mappings being
>>>>>> generated
>>>>>>>> in
>>>>>>>>>> order to achieve above modified id- and version-elements?
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>> Björn
>>>>>>>>>>
>>>>>>>>>> PS. Versions used and settings:
>>>>>>>>>> - Eclipse IDE 3.2.1
>>>>>>>>>> - EMF 2.2.2
>>>>>>>>>> - Teneo 0.7.5 Maintenance Build
>>>>>>>>>> - Hibernate 3.2
>>>>>>>>>> - MySql and/or Derby embedded
>>>>>>>>>> - Persistence properties set in the EditorPlugin:
>>>>>>>>>>
>>>>>>>>>>
>>> persistenceProperties.setProperty(PersistenceOptions.ID_COLU MN_NAME,
>>>>>>>> "id");
> persistenceProperties.setProperty(PersistenceOptions.VERSION _COLUMN_NAME,
>>>>>>>>>> "version");
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>> --
>>>>>>>>>
>>>>>>>>> With Regards, Martin Taal
>>>>>>>>>
>>>>>>>>> Springsite/Elver.org
>>>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>>>> The Netherlands
>>>>>>>>> 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
>>>>>>> --
>>>>>>>
>>>>>>> With Regards, Martin Taal
>>>>>>>
>>>>>>> Springsite/Elver.org
>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>> The Netherlands
>>>>>>> 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
>>>>> --
>>>>>
>>>>> With Regards, Martin Taal
>>>>>
>>>>> Springsite/Elver.org
>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>> The Netherlands
>>>>> 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
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Possible to Override Generation of hibernate.hbm.xml? [message #602973 is a reply to message #72941] |
Tue, 27 February 2007 17:06 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Björn,
In Teneo annotations are not specified in the java code but in the model (ecore or xsd) or in a
separate xml.
So the @Id and @GeneratedValue(strategy=GenerationType.AUTO) annotations should be specified there.
If your id attributes all use an EDataType defined by yourselve then you can add the annotations to
the EDataType (so one place instead of at each attribute).
See also here:
http://www.elver.org/hibernate/ejb3_format.html
http://www.elver.org/hibernate/ejb3_examples.html
gr. Martin
Björn Sundin wrote:
> Hi,
>
> I have some problems getting in control of the id and version columns in my
> project. I need to have those attributes both in the ecore and in my model
> interface (non synthetic), in the EMF-Editor, however, they are not visible.
>
> I tried to set persistency annotations in the model interfaces with little
> success:
>
> FOR THE ID COLUMN:
> /**
> * @model id="true" required="true"
> * @generated
> */
> @Id @GeneratedValue(strategy=GenerationType.AUTO)
> int getId();
>
> /**
> * @generated
> */
> void setId(int value);
>
> RESULT: org.hibernate.id.IdentifierGenerationException: ids for this class
> must be manually assigned before calling save()
> (I notice that the generated PK `id` is auto_increment in
> MySql)
>
> FOR THE VERSION COLUMN:
> /**
> * @model required="true"
> * @generated
> */
> @Version
> int getVersion();
>
> /**
> * @generated
> */
> void setVersion(int value);
>
> RESULT: org.hibernate.MappingException: Duplicate property mapping of
> version found
>
> As I will have quite some tables in my model I'm not so keen in modifying
> all generated model interfaces in order to add any annotations. What I
> rather would like is to utilize the Teneo utility and so generate EMF -
> Hibernate OR mapping direct from the ecore file. In order to do that I have
> added persistenceProperties.setProperty(PersistenceOptions.USE_MAP PING_FILE,
> "true"); to the persistency property in the EditorPlugin. The generated
> hibernate.hbm.xml has anyway to be modified in the following way:
>
> GENERATED:
> <id name="id" type="int">
> <column not-null="true" unique="false" name="`id`"/>
> </id>
>
> MODIFIED:
> <id name="id" type="int" column="id" unsaved-value="0">
> <generator class="identity"/>
> </id>
>
> GENERATED:
> <version name="version" column="version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
> ler">
> <meta attribute="syntheticVersion">true</meta>
> </version>
>
> MODIFIED:
> <version name="version" column="version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
> ler"/>
>
> With the above modifications my EMF-Editor is working and I have no problems
> persisting the model objects to the database. Ids are generated and version
> is incremented.
>
> My question is if one somehow can override the mappings being generated in
> order to achieve above modified id- and version-elements?
>
> Thanks,
> Björn
>
> PS. Versions used and settings:
> - Eclipse IDE 3.2.1
> - EMF 2.2.2
> - Teneo 0.7.5 Maintenance Build
> - Hibernate 3.2
> - MySql and/or Derby embedded
> - Persistence properties set in the EditorPlugin:
>
> persistenceProperties.setProperty(PersistenceOptions.ID_COLU MN_NAME, "id");
>
> persistenceProperties.setProperty(PersistenceOptions.VERSION _COLUMN_NAME,
> "version");
>
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Possible to Override Generation of hibernate.hbm.xml? [message #602977 is a reply to message #72985] |
Wed, 28 February 2007 13:50 |
Eclipse User |
|
|
|
Originally posted by: bsu.bergauer.ch
Hi Martin,
Thanks for your reply. It definitely brought me on the right path and so I
decided to define my own id and version datatypes in ecore:
<eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
instanceClassName="int">
<eAnnotations source="teneo.jpa/Id">
<details key="appinfo"
value="@GeneratedValue(strategy="AUTO")"/ >
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
instanceClassName="int">
<eAnnotations source="teneo.jpa/Version">
<!-- <details key="appinfo" value="@Version"/> -->
</eAnnotations>
</eClassifiers>
Those two datatypes are referenced in i.e StatusType:
<eClassifiers xsi:type="ecore:EClass" name="StatusType">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
lowerBound="1"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
lowerBound="1"
eType="#//bergauer/rcp/amset/model/datatypes/AmsetId"
iD="true"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="version"
lowerBound="1"
eType="#//bergauer/rcp/amset/model/datatypes/AmsetVersion"/ >
</eClassifiers>
I now have the following results:
PersistenceOptions.USE_MAPPING_FILE set true:
- The hibernate.hbm.xml I now have the id-element with generator,
non-synthetic. Id is generated as expected
- The version attribute that I define in ecore isn't recognized with
annotation yet. In the hibernate.hbm.xml I have one version-element (with
synthetic set true) and in the database I get two fields e_version and
version. The PersistenceOptions.ALWAYS_VERSION is set false in the
EditorPlugin.
<class entity-name="StatusType" abstract="false" lazy="false"
discriminator-value="StatusType" table="`statustype`">
<meta attribute="eclassName">StatusType</meta>
<meta
attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
/meta>
<id name="id" type="int">
<column not-null="true" unique="false" name="`id`"/>
<generator class="native"/>
</id>
<discriminator column="`dtype`" type="string"/>
<version name="e_version" column="e_version"
access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
ler">
<meta attribute="syntheticVersion">true</meta>
</version>
<property name="name" lazy="false" insert="true" update="true"
not-null="true" unique="false" type="java.lang.String">
<column not-null="true" unique="false" name="`name`"/>
</property>
</class>
PersistenceOptions.USE_MAPPING_FILE set false:
Neither id nor version work is reqognized. In the in-menory mapping I
have no generator element for the id-element:
<class entity-name="StatusType" abstract="false" lazy="false"
discriminator-value="StatusType" table="`statustype`">
<meta attribute="eclassName">StatusType</meta>
<meta
attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
/meta>
<id name="id" type="int">
<column not-null="true" unique="false" name="`id`"/>
</id>
<discriminator column="`dtype`" type="string"/>
<property name="name" lazy="false" insert="true" update="true"
not-null="true" unique="false" type="java.lang.String">
<column not-null="true" unique="false" name="`name`"/>
</property>
<property name="version" lazy="false" insert="true" update="true"
not-null="true" unique="false" type="int">
<column not-null="true" unique="false" name="`version`"/>
</property>
</class>
The solution using the hibernate.hbm.xml seems to be the better way, so I
think I will go on using PersistenceOptions.USE_MAPPING_FILE=true.
Apperently I'm doing something wrong with the version though. Am I
overlooking something obvious?
cheers,
Bj
|
|
|
Re: [Teneo] Possible to Override Generation of hibernate.hbm.xml? [message #602979 is a reply to message #72995] |
Wed, 28 February 2007 14:16 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Björn,
Afaics the <details...> tag in the eAnnotations of the AmsetVersion EDataType is commented out using
xml comment characters (<!-- and -->). Could that be a reason?
Also the id annotation does not seem to be completely correct. The source should teneo.jpa and then
the value should also contain the @Id annotation.
There should be no difference in generating the mapping file manually and then use that or the
automatic mapping in-memory (it also generates an in-memory mapping). I would suggest to use the
automatic in-memory mapping until you want to do extensive manual changes (for example to map to a
current db schema).
gr. Martin
Björn Sundin wrote:
> Hi Martin,
>
> Thanks for your reply. It definitely brought me on the right path and so I
> decided to define my own id and version datatypes in ecore:
>
> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
> instanceClassName="int">
> <eAnnotations source="teneo.jpa/Id">
> <details key="appinfo"
> value="@GeneratedValue(strategy="AUTO")"/ >
> </eAnnotations>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
> instanceClassName="int">
> <eAnnotations source="teneo.jpa/Version">
> <!-- <details key="appinfo" value="@Version"/> -->
> </eAnnotations>
> </eClassifiers>
>
> Those two datatypes are referenced in i.e StatusType:
>
> <eClassifiers xsi:type="ecore:EClass" name="StatusType">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> lowerBound="1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
> lowerBound="1"
> eType="#//bergauer/rcp/amset/model/datatypes/AmsetId"
> iD="true"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="version"
> lowerBound="1"
> eType="#//bergauer/rcp/amset/model/datatypes/AmsetVersion"/ >
> </eClassifiers>
>
>
> I now have the following results:
>
> PersistenceOptions.USE_MAPPING_FILE set true:
> - The hibernate.hbm.xml I now have the id-element with generator,
> non-synthetic. Id is generated as expected
> - The version attribute that I define in ecore isn't recognized with
> annotation yet. In the hibernate.hbm.xml I have one version-element (with
> synthetic set true) and in the database I get two fields e_version and
> version. The PersistenceOptions.ALWAYS_VERSION is set false in the
> EditorPlugin.
>
> <class entity-name="StatusType" abstract="false" lazy="false"
> discriminator-value="StatusType" table="`statustype`">
> <meta attribute="eclassName">StatusType</meta>
> <meta
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
> /meta>
> <id name="id" type="int">
> <column not-null="true" unique="false" name="`id`"/>
> <generator class="native"/>
> </id>
> <discriminator column="`dtype`" type="string"/>
> <version name="e_version" column="e_version"
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
> ler">
> <meta attribute="syntheticVersion">true</meta>
> </version>
> <property name="name" lazy="false" insert="true" update="true"
> not-null="true" unique="false" type="java.lang.String">
> <column not-null="true" unique="false" name="`name`"/>
> </property>
> </class>
>
> PersistenceOptions.USE_MAPPING_FILE set false:
> Neither id nor version work is reqognized. In the in-menory mapping I
> have no generator element for the id-element:
>
> <class entity-name="StatusType" abstract="false" lazy="false"
> discriminator-value="StatusType" table="`statustype`">
> <meta attribute="eclassName">StatusType</meta>
> <meta
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
> /meta>
> <id name="id" type="int">
> <column not-null="true" unique="false" name="`id`"/>
> </id>
> <discriminator column="`dtype`" type="string"/>
> <property name="name" lazy="false" insert="true" update="true"
> not-null="true" unique="false" type="java.lang.String">
> <column not-null="true" unique="false" name="`name`"/>
> </property>
> <property name="version" lazy="false" insert="true" update="true"
> not-null="true" unique="false" type="int">
> <column not-null="true" unique="false" name="`version`"/>
> </property>
> </class>
>
> The solution using the hibernate.hbm.xml seems to be the better way, so I
> think I will go on using PersistenceOptions.USE_MAPPING_FILE=true.
> Apperently I'm doing something wrong with the version though. Am I
> overlooking something obvious?
>
> cheers,
> Björn
>
> ref: [Teneo] Setting Id generator from ecore file
> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
> news:es1oej$v6h$1@utils.eclipse.org...
>> Hi Björn,
>> In Teneo annotations are not specified in the java code but in the model
> (ecore or xsd) or in a
>> separate xml.
>> So the @Id and @GeneratedValue(strategy=GenerationType.AUTO) annotations
> should be specified there.
>> If your id attributes all use an EDataType defined by yourselve then you
> can add the annotations to
>> the EDataType (so one place instead of at each attribute).
>>
>> See also here:
>> http://www.elver.org/hibernate/ejb3_format.html
>> http://www.elver.org/hibernate/ejb3_examples.html
>>
>> gr. Martin
>>
>> Björn Sundin wrote:
>>> Hi,
>>>
>>> I have some problems getting in control of the id and version columns in
> my
>>> project. I need to have those attributes both in the ecore and in my
> model
>>> interface (non synthetic), in the EMF-Editor, however, they are not
> visible.
>>> I tried to set persistency annotations in the model interfaces with
> little
>>> success:
>>>
>>> FOR THE ID COLUMN:
>>> /**
>>> * @model id="true" required="true"
>>> * @generated
>>> */
>>> @Id @GeneratedValue(strategy=GenerationType.AUTO)
>>> int getId();
>>>
>>> /**
>>> * @generated
>>> */
>>> void setId(int value);
>>>
>>> RESULT: org.hibernate.id.IdentifierGenerationException: ids for this
> class
>>> must be manually assigned before calling save()
>>> (I notice that the generated PK `id` is auto_increment
> in
>>> MySql)
>>>
>>> FOR THE VERSION COLUMN:
>>> /**
>>> * @model required="true"
>>> * @generated
>>> */
>>> @Version
>>> int getVersion();
>>>
>>> /**
>>> * @generated
>>> */
>>> void setVersion(int value);
>>>
>>> RESULT: org.hibernate.MappingException: Duplicate property mapping of
>>> version found
>>>
>>> As I will have quite some tables in my model I'm not so keen in
> modifying
>>> all generated model interfaces in order to add any annotations. What I
>>> rather would like is to utilize the Teneo utility and so generate EMF -
>>> Hibernate OR mapping direct from the ecore file. In order to do that I
> have
>>> added
> persistenceProperties.setProperty(PersistenceOptions.USE_MAP PING_FILE,
>>> "true"); to the persistency property in the EditorPlugin. The generated
>>> hibernate.hbm.xml has anyway to be modified in the following way:
>>>
>>> GENERATED:
>>> <id name="id" type="int">
>>> <column not-null="true" unique="false" name="`id`"/>
>>> </id>
>>>
>>> MODIFIED:
>>> <id name="id" type="int" column="id" unsaved-value="0">
>>> <generator class="identity"/>
>>> </id>
>>>
>>> GENERATED:
>>> <version name="version" column="version"
>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>> ler">
>>> <meta attribute="syntheticVersion">true</meta>
>>> </version>
>>>
>>> MODIFIED:
>>> <version name="version" column="version"
>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>> ler"/>
>>>
>>> With the above modifications my EMF-Editor is working and I have no
> problems
>>> persisting the model objects to the database. Ids are generated and
> version
>>> is incremented.
>>>
>>> My question is if one somehow can override the mappings being generated
> in
>>> order to achieve above modified id- and version-elements?
>>>
>>> Thanks,
>>> Björn
>>>
>>> PS. Versions used and settings:
>>> - Eclipse IDE 3.2.1
>>> - EMF 2.2.2
>>> - Teneo 0.7.5 Maintenance Build
>>> - Hibernate 3.2
>>> - MySql and/or Derby embedded
>>> - Persistence properties set in the EditorPlugin:
>>>
>>> persistenceProperties.setProperty(PersistenceOptions.ID_COLU MN_NAME,
> "id");
>>>
> persistenceProperties.setProperty(PersistenceOptions.VERSION _COLUMN_NAME,
>>> "version");
>>>
>>>
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Possible to Override Generation of hibernate.hbm.xml? [message #602983 is a reply to message #73013] |
Wed, 28 February 2007 15:51 |
Eclipse User |
|
|
|
Originally posted by: bsu.bergauer.ch
Hi Martin,
Well the out-commented element is an artifact from my first try. Oddly
enough I think it was about how you meant it should look like :
<eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
instanceClassName="int">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@Id
@GeneratedValue(strategy="AUTO")"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
instanceClassName="int">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@Version"/>
</eAnnotations>
</eClassifiers>
It didn't work with the automatic mapping (and I think I missed out testing
it with the hibernate.hbm.xml) so I abandoned it and found other suggestions
in the newsgroup extending teneo.jpa to teneo.jpa/Id... :o/
After having reimplemented the eDataTypes, as above, both Id and Version
works well using the hibernate.hbm.xml! :) The automatic mapping, though,
still doesn't recognize the annotations:
hibernate.hbm.xml:
<class entity-name="StatusType" abstract="false" lazy="false"
discriminator-value="StatusType" table="`statustype`">
<meta attribute="eclassName">StatusType</meta>
<meta
attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
/meta>
<id name="id" type="int">
<column not-null="true" unique="false" name="`id`"/>
<generator class="native"/>
</id>
<discriminator column="`dtype`" type="string"/>
<version name="version" type="int">
<column not-null="true" unique="false" name="`version`"/>
</version>
<property name="name" lazy="false" insert="true" update="true"
not-null="true" unique="false" type="java.lang.String">
<column not-null="true" unique="false" name="`name`"/>
</property>
</class>
automatic mapping:
<class entity-name="StatusType" abstract="false" lazy="false"
discriminator-value="StatusType" table="`statustype`">
<meta attribute="eclassName">StatusType</meta>
<meta
attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
/meta>
<id name="id" type="int">
<column not-null="true" unique="false" name="`id`"/>
</id>
<discriminator column="`dtype`" type="string"/>
<property name="name" lazy="false" insert="true" update="true"
not-null="true" unique="false" type="java.lang.String">
<column not-null="true" unique="false" name="`name`"/>
</property>
<property name="version" lazy="false" insert="true" update="true"
not-null="true" unique="false" type="int">
<column not-null="true" unique="false" name="`version`"/>
</property>
</class>
Could it have to do with the version of Teneo that I use? I'm currently
using Teneo 0.7.5 Maintenance Build. I did download version 0.8.0 but had to
deactivate it as I'm using Eclipse 3.2.1.
Greetings,
Bj
|
|
|
Re: [Teneo] Possible to Override Generation of hibernate.hbm.xml? [message #602987 is a reply to message #73035] |
Wed, 28 February 2007 15:56 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Björn,
What could explain the difference is that after a change in the ecore (like adding an annotation)
you have to regenerate the java model code to get the change in ecore to the runtime layer.
For the automatic mapping the ecore model is not read from the ecore file but from the in-memory
ecore representation. This in-memory representation is created by the generated PackageImpl and can
be out of sync with the ecore file.
So can you try again (if you like) after regenerating the java model code?
gr. Martin
Björn Sundin wrote:
> Hi Martin,
>
> Well the out-commented element is an artifact from my first try. Oddly
> enough I think it was about how you meant it should look like :
>
> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
> instanceClassName="int">
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value="@Id
> @GeneratedValue(strategy="AUTO")"/>
> </eAnnotations>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
> instanceClassName="int">
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value="@Version"/>
> </eAnnotations>
> </eClassifiers>
>
> It didn't work with the automatic mapping (and I think I missed out testing
> it with the hibernate.hbm.xml) so I abandoned it and found other suggestions
> in the newsgroup extending teneo.jpa to teneo.jpa/Id... :o/
>
> After having reimplemented the eDataTypes, as above, both Id and Version
> works well using the hibernate.hbm.xml! :) The automatic mapping, though,
> still doesn't recognize the annotations:
>
> hibernate.hbm.xml:
>
> <class entity-name="StatusType" abstract="false" lazy="false"
> discriminator-value="StatusType" table="`statustype`">
> <meta attribute="eclassName">StatusType</meta>
> <meta
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
> /meta>
> <id name="id" type="int">
> <column not-null="true" unique="false" name="`id`"/>
> <generator class="native"/>
> </id>
> <discriminator column="`dtype`" type="string"/>
> <version name="version" type="int">
> <column not-null="true" unique="false" name="`version`"/>
> </version>
> <property name="name" lazy="false" insert="true" update="true"
> not-null="true" unique="false" type="java.lang.String">
> <column not-null="true" unique="false" name="`name`"/>
> </property>
> </class>
>
> automatic mapping:
>
> <class entity-name="StatusType" abstract="false" lazy="false"
> discriminator-value="StatusType" table="`statustype`">
> <meta attribute="eclassName">StatusType</meta>
> <meta
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
> /meta>
> <id name="id" type="int">
> <column not-null="true" unique="false" name="`id`"/>
> </id>
> <discriminator column="`dtype`" type="string"/>
> <property name="name" lazy="false" insert="true" update="true"
> not-null="true" unique="false" type="java.lang.String">
> <column not-null="true" unique="false" name="`name`"/>
> </property>
> <property name="version" lazy="false" insert="true" update="true"
> not-null="true" unique="false" type="int">
> <column not-null="true" unique="false" name="`version`"/>
> </property>
> </class>
>
> Could it have to do with the version of Teneo that I use? I'm currently
> using Teneo 0.7.5 Maintenance Build. I did download version 0.8.0 but had to
> deactivate it as I'm using Eclipse 3.2.1.
>
> Greetings,
> Björn
>
> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
> news:es42sn$jr2$1@utils.eclipse.org...
>> Hi Björn,
>> Afaics the <details...> tag in the eAnnotations of the AmsetVersion
> EDataType is commented out using
>> xml comment characters (<!-- and -->). Could that be a reason?
>>
>> Also the id annotation does not seem to be completely correct. The source
> should teneo.jpa and then
>> the value should also contain the @Id annotation.
>>
>> There should be no difference in generating the mapping file manually and
> then use that or the
>> automatic mapping in-memory (it also generates an in-memory mapping). I
> would suggest to use the
>> automatic in-memory mapping until you want to do extensive manual changes
> (for example to map to a
>> current db schema).
>>
>> gr. Martin
>>
>> Björn Sundin wrote:
>>> Hi Martin,
>>>
>>> Thanks for your reply. It definitely brought me on the right path and so
> I
>>> decided to define my own id and version datatypes in ecore:
>>>
>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
>>> instanceClassName="int">
>>> <eAnnotations source="teneo.jpa/Id">
>>> <details key="appinfo"
>>> value="@GeneratedValue(strategy="AUTO")"/ >
>>> </eAnnotations>
>>> </eClassifiers>
>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
>>> instanceClassName="int">
>>> <eAnnotations source="teneo.jpa/Version">
>>> <!-- <details key="appinfo" value="@Version"/> -->
>>> </eAnnotations>
>>> </eClassifiers>
>>>
>>> Those two datatypes are referenced in i.e StatusType:
>>>
>>> <eClassifiers xsi:type="ecore:EClass" name="StatusType">
>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
>>> lowerBound="1"
>>> eType="ecore:EDataType
>>> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
>>> lowerBound="1"
>>> eType="#//bergauer/rcp/amset/model/datatypes/AmsetId"
>>> iD="true"/>
>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="version"
>>> lowerBound="1"
>>> eType="#//bergauer/rcp/amset/model/datatypes/AmsetVersion"/ >
>>> </eClassifiers>
>>>
>>>
>>> I now have the following results:
>>>
>>> PersistenceOptions.USE_MAPPING_FILE set true:
>>> - The hibernate.hbm.xml I now have the id-element with generator,
>>> non-synthetic. Id is generated as expected
>>> - The version attribute that I define in ecore isn't recognized with
>>> annotation yet. In the hibernate.hbm.xml I have one version-element
> (with
>>> synthetic set true) and in the database I get two fields e_version and
>>> version. The PersistenceOptions.ALWAYS_VERSION is set false in the
>>> EditorPlugin.
>>>
>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>> discriminator-value="StatusType" table="`statustype`">
>>> <meta attribute="eclassName">StatusType</meta>
>>> <meta
>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>> /meta>
>>> <id name="id" type="int">
>>> <column not-null="true" unique="false" name="`id`"/>
>>> <generator class="native"/>
>>> </id>
>>> <discriminator column="`dtype`" type="string"/>
>>> <version name="e_version" column="e_version"
>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>> ler">
>>> <meta attribute="syntheticVersion">true</meta>
>>> </version>
>>> <property name="name" lazy="false" insert="true" update="true"
>>> not-null="true" unique="false" type="java.lang.String">
>>> <column not-null="true" unique="false" name="`name`"/>
>>> </property>
>>> </class>
>>>
>>> PersistenceOptions.USE_MAPPING_FILE set false:
>>> Neither id nor version work is reqognized. In the in-menory mapping
> I
>>> have no generator element for the id-element:
>>>
>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>> discriminator-value="StatusType" table="`statustype`">
>>> <meta attribute="eclassName">StatusType</meta>
>>> <meta
>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>> /meta>
>>> <id name="id" type="int">
>>> <column not-null="true" unique="false" name="`id`"/>
>>> </id>
>>> <discriminator column="`dtype`" type="string"/>
>>> <property name="name" lazy="false" insert="true" update="true"
>>> not-null="true" unique="false" type="java.lang.String">
>>> <column not-null="true" unique="false" name="`name`"/>
>>> </property>
>>> <property name="version" lazy="false" insert="true"
> update="true"
>>> not-null="true" unique="false" type="int">
>>> <column not-null="true" unique="false" name="`version`"/>
>>> </property>
>>> </class>
>>>
>>> The solution using the hibernate.hbm.xml seems to be the better way, so
> I
>>> think I will go on using PersistenceOptions.USE_MAPPING_FILE=true.
>>> Apperently I'm doing something wrong with the version though. Am I
>>> overlooking something obvious?
>>>
>>> cheers,
>>> Björn
>>>
>>> ref: [Teneo] Setting Id generator from ecore file
>>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>>> news:es1oej$v6h$1@utils.eclipse.org...
>>>> Hi Björn,
>>>> In Teneo annotations are not specified in the java code but in the
> model
>>> (ecore or xsd) or in a
>>>> separate xml.
>>>> So the @Id and @GeneratedValue(strategy=GenerationType.AUTO)
> annotations
>>> should be specified there.
>>>> If your id attributes all use an EDataType defined by yourselve then
> you
>>> can add the annotations to
>>>> the EDataType (so one place instead of at each attribute).
>>>>
>>>> See also here:
>>>> http://www.elver.org/hibernate/ejb3_format.html
>>>> http://www.elver.org/hibernate/ejb3_examples.html
>>>>
>>>> gr. Martin
>>>>
>>>> Björn Sundin wrote:
>>>>> Hi,
>>>>>
>>>>> I have some problems getting in control of the id and version columns
> in
>>> my
>>>>> project. I need to have those attributes both in the ecore and in my
>>> model
>>>>> interface (non synthetic), in the EMF-Editor, however, they are not
>>> visible.
>>>>> I tried to set persistency annotations in the model interfaces with
>>> little
>>>>> success:
>>>>>
>>>>> FOR THE ID COLUMN:
>>>>> /**
>>>>> * @model id="true" required="true"
>>>>> * @generated
>>>>> */
>>>>> @Id @GeneratedValue(strategy=GenerationType.AUTO)
>>>>> int getId();
>>>>>
>>>>> /**
>>>>> * @generated
>>>>> */
>>>>> void setId(int value);
>>>>>
>>>>> RESULT: org.hibernate.id.IdentifierGenerationException: ids for this
>>> class
>>>>> must be manually assigned before calling save()
>>>>> (I notice that the generated PK `id` is auto_increment
>>> in
>>>>> MySql)
>>>>>
>>>>> FOR THE VERSION COLUMN:
>>>>> /**
>>>>> * @model required="true"
>>>>> * @generated
>>>>> */
>>>>> @Version
>>>>> int getVersion();
>>>>>
>>>>> /**
>>>>> * @generated
>>>>> */
>>>>> void setVersion(int value);
>>>>>
>>>>> RESULT: org.hibernate.MappingException: Duplicate property mapping of
>>>>> version found
>>>>>
>>>>> As I will have quite some tables in my model I'm not so keen in
>>> modifying
>>>>> all generated model interfaces in order to add any annotations. What I
>>>>> rather would like is to utilize the Teneo utility and so generate
> EMF -
>>>>> Hibernate OR mapping direct from the ecore file. In order to do that I
>>> have
>>>>> added
>>> persistenceProperties.setProperty(PersistenceOptions.USE_MAP PING_FILE,
>>>>> "true"); to the persistency property in the EditorPlugin. The
> generated
>>>>> hibernate.hbm.xml has anyway to be modified in the following way:
>>>>>
>>>>> GENERATED:
>>>>> <id name="id" type="int">
>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>> </id>
>>>>>
>>>>> MODIFIED:
>>>>> <id name="id" type="int" column="id" unsaved-value="0">
>>>>> <generator class="identity"/>
>>>>> </id>
>>>>>
>>>>> GENERATED:
>>>>> <version name="version" column="version"
>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>> ler">
>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>> </version>
>>>>>
>>>>> MODIFIED:
>>>>> <version name="version" column="version"
>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>> ler"/>
>>>>>
>>>>> With the above modifications my EMF-Editor is working and I have no
>>> problems
>>>>> persisting the model objects to the database. Ids are generated and
>>> version
>>>>> is incremented.
>>>>>
>>>>> My question is if one somehow can override the mappings being
> generated
>>> in
>>>>> order to achieve above modified id- and version-elements?
>>>>>
>>>>> Thanks,
>>>>> Björn
>>>>>
>>>>> PS. Versions used and settings:
>>>>> - Eclipse IDE 3.2.1
>>>>> - EMF 2.2.2
>>>>> - Teneo 0.7.5 Maintenance Build
>>>>> - Hibernate 3.2
>>>>> - MySql and/or Derby embedded
>>>>> - Persistence properties set in the EditorPlugin:
>>>>>
>>>>> persistenceProperties.setProperty(PersistenceOptions.ID_COLU MN_NAME,
>>> "id");
> persistenceProperties.setProperty(PersistenceOptions.VERSION _COLUMN_NAME,
>>>>> "version");
>>>>>
>>>>>
>>>>>
>>>> --
>>>>
>>>> With Regards, Martin Taal
>>>>
>>>> Springsite/Elver.org
>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>> The Netherlands
>>>> 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
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Possible to Override Generation of hibernate.hbm.xml? [message #602990 is a reply to message #73053] |
Wed, 28 February 2007 16:16 |
Eclipse User |
|
|
|
Originally posted by: bsu.bergauer.ch
Hi Martin,
I use to regenerate all code (model, edit, editor) every time I make a
change to the ecore model. Now I even deleted the model code and generated
it from scratch. I'm sorry to say that it still is a problem with the
autogenerated mapping. It's exactly the same as in my prevoious post.
Could it be a problem that the eDataTypes are in another package than the
model code?
Greetings,
Bj
|
|
| |
Re: [Teneo] Possible to Override Generation of hibernate.hbm.xml? [message #602996 is a reply to message #73096] |
Wed, 28 February 2007 17:05 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
No problem. Actually, I am not sure why you would need to move the edatatype to the same package.
When you said regenerate, did you regenerate the model code of both epackages?
gr. Martin
Björn Sundin wrote:
> I just moved the eDataTypes to the same package as the model code and the
> autogenerated mapping works! I guess I'm lucky not sitting in your office
> right now...
>
> Greetings,
> Björn
>
>
> "Björn Sundin" <bsu@bergauer.ch> schrieb im Newsbeitrag
> news:es49s3$403$1@utils.eclipse.org...
>> Hi Martin,
>>
>> I use to regenerate all code (model, edit, editor) every time I make a
>> change to the ecore model. Now I even deleted the model code and generated
>> it from scratch. I'm sorry to say that it still is a problem with the
>> autogenerated mapping. It's exactly the same as in my prevoious post.
>> Could it be a problem that the eDataTypes are in another package than the
>> model code?
>>
>> Greetings,
>> Björn
>>
>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>> news:es48o3$ak$1@utils.eclipse.org...
>>> Hi Björn,
>>> What could explain the difference is that after a change in the ecore
>> (like adding an annotation)
>>> you have to regenerate the java model code to get the change in ecore to
>> the runtime layer.
>>> For the automatic mapping the ecore model is not read from the ecore
> file
>> but from the in-memory
>>> ecore representation. This in-memory representation is created by the
>> generated PackageImpl and can
>>> be out of sync with the ecore file.
>>> So can you try again (if you like) after regenerating the java model
> code?
>>> gr. Martin
>>>
>>> Björn Sundin wrote:
>>>> Hi Martin,
>>>>
>>>> Well the out-commented element is an artifact from my first try. Oddly
>>>> enough I think it was about how you meant it should look like :
>>>>
>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
>>>> instanceClassName="int">
>>>> <eAnnotations source="teneo.jpa">
>>>> <details key="appinfo" value="@Id
>>>> @GeneratedValue(strategy="AUTO")"/>
>>>> </eAnnotations>
>>>> </eClassifiers>
>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
>>>> instanceClassName="int">
>>>> <eAnnotations source="teneo.jpa">
>>>> <details key="appinfo" value="@Version"/>
>>>> </eAnnotations>
>>>> </eClassifiers>
>>>>
>>>> It didn't work with the automatic mapping (and I think I missed out
>> testing
>>>> it with the hibernate.hbm.xml) so I abandoned it and found other
>> suggestions
>>>> in the newsgroup extending teneo.jpa to teneo.jpa/Id... :o/
>>>>
>>>> After having reimplemented the eDataTypes, as above, both Id and
> Version
>>>> works well using the hibernate.hbm.xml! :) The automatic mapping,
>> though,
>>>> still doesn't recognize the annotations:
>>>>
>>>> hibernate.hbm.xml:
>>>>
>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>> discriminator-value="StatusType" table="`statustype`">
>>>> <meta attribute="eclassName">StatusType</meta>
>>>> <meta
>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>> /meta>
>>>> <id name="id" type="int">
>>>> <column not-null="true" unique="false" name="`id`"/>
>>>> <generator class="native"/>
>>>> </id>
>>>> <discriminator column="`dtype`" type="string"/>
>>>> <version name="version" type="int">
>>>> <column not-null="true" unique="false" name="`version`"/>
>>>> </version>
>>>> <property name="name" lazy="false" insert="true" update="true"
>>>> not-null="true" unique="false" type="java.lang.String">
>>>> <column not-null="true" unique="false" name="`name`"/>
>>>> </property>
>>>> </class>
>>>>
>>>> automatic mapping:
>>>>
>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>> discriminator-value="StatusType" table="`statustype`">
>>>> <meta attribute="eclassName">StatusType</meta>
>>>> <meta
>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>> /meta>
>>>> <id name="id" type="int">
>>>> <column not-null="true" unique="false" name="`id`"/>
>>>> </id>
>>>> <discriminator column="`dtype`" type="string"/>
>>>> <property name="name" lazy="false" insert="true" update="true"
>>>> not-null="true" unique="false" type="java.lang.String">
>>>> <column not-null="true" unique="false" name="`name`"/>
>>>> </property>
>>>> <property name="version" lazy="false" insert="true"
>> update="true"
>>>> not-null="true" unique="false" type="int">
>>>> <column not-null="true" unique="false" name="`version`"/>
>>>> </property>
>>>> </class>
>>>>
>>>> Could it have to do with the version of Teneo that I use? I'm
> currently
>>>> using Teneo 0.7.5 Maintenance Build. I did download version 0.8.0 but
>> had to
>>>> deactivate it as I'm using Eclipse 3.2.1.
>>>>
>>>> Greetings,
>>>> Björn
>>>>
>>>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>>>> news:es42sn$jr2$1@utils.eclipse.org...
>>>>> Hi Björn,
>>>>> Afaics the <details...> tag in the eAnnotations of the AmsetVersion
>>>> EDataType is commented out using
>>>>> xml comment characters (<!-- and -->). Could that be a reason?
>>>>>
>>>>> Also the id annotation does not seem to be completely correct. The
>> source
>>>> should teneo.jpa and then
>>>>> the value should also contain the @Id annotation.
>>>>>
>>>>> There should be no difference in generating the mapping file manually
>> and
>>>> then use that or the
>>>>> automatic mapping in-memory (it also generates an in-memory mapping).
> I
>>>> would suggest to use the
>>>>> automatic in-memory mapping until you want to do extensive manual
>> changes
>>>> (for example to map to a
>>>>> current db schema).
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> Björn Sundin wrote:
>>>>>> Hi Martin,
>>>>>>
>>>>>> Thanks for your reply. It definitely brought me on the right path
> and
>> so
>>>> I
>>>>>> decided to define my own id and version datatypes in ecore:
>>>>>>
>>>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
>>>>>> instanceClassName="int">
>>>>>> <eAnnotations source="teneo.jpa/Id">
>>>>>> <details key="appinfo"
>>>>>> value="@GeneratedValue(strategy="AUTO")"/ >
>>>>>> </eAnnotations>
>>>>>> </eClassifiers>
>>>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
>>>>>> instanceClassName="int">
>>>>>> <eAnnotations source="teneo.jpa/Version">
>>>>>> <!-- <details key="appinfo" value="@Version"/> -->
>>>>>> </eAnnotations>
>>>>>> </eClassifiers>
>>>>>>
>>>>>> Those two datatypes are referenced in i.e StatusType:
>>>>>>
>>>>>> <eClassifiers xsi:type="ecore:EClass" name="StatusType">
>>>>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
>>>>>> lowerBound="1"
>>>>>> eType="ecore:EDataType
>>>>>> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
>>>>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
>>>>>> lowerBound="1"
>>>>>> eType="#//bergauer/rcp/amset/model/datatypes/AmsetId"
>>>>>> iD="true"/>
>>>>>> <eStructuralFeatures xsi:type="ecore:EAttribute"
>> name="version"
>>>>>> lowerBound="1"
>>>>>>
>> eType="#//bergauer/rcp/amset/model/datatypes/AmsetVersion"/ >
>>>>>> </eClassifiers>
>>>>>>
>>>>>>
>>>>>> I now have the following results:
>>>>>>
>>>>>> PersistenceOptions.USE_MAPPING_FILE set true:
>>>>>> - The hibernate.hbm.xml I now have the id-element with
> generator,
>>>>>> non-synthetic. Id is generated as expected
>>>>>> - The version attribute that I define in ecore isn't recognized
>> with
>>>>>> annotation yet. In the hibernate.hbm.xml I have one version-element
>>>> (with
>>>>>> synthetic set true) and in the database I get two fields e_version
> and
>>>>>> version. The PersistenceOptions.ALWAYS_VERSION is set false in the
>>>>>> EditorPlugin.
>>>>>>
>>>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>>>> discriminator-value="StatusType" table="`statustype`">
>>>>>> <meta attribute="eclassName">StatusType</meta>
>>>>>> <meta
>>>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>>>> /meta>
>>>>>> <id name="id" type="int">
>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>> <generator class="native"/>
>>>>>> </id>
>>>>>> <discriminator column="`dtype`" type="string"/>
>>>>>> <version name="e_version" column="e_version"
>>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>>> ler">
>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>> </version>
>>>>>> <property name="name" lazy="false" insert="true"
> update="true"
>>>>>> not-null="true" unique="false" type="java.lang.String">
>>>>>> <column not-null="true" unique="false" name="`name`"/>
>>>>>> </property>
>>>>>> </class>
>>>>>>
>>>>>> PersistenceOptions.USE_MAPPING_FILE set false:
>>>>>> Neither id nor version work is reqognized. In the in-menory
>> mapping
>>>> I
>>>>>> have no generator element for the id-element:
>>>>>>
>>>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>>>> discriminator-value="StatusType" table="`statustype`">
>>>>>> <meta attribute="eclassName">StatusType</meta>
>>>>>> <meta
>>>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>>>> /meta>
>>>>>> <id name="id" type="int">
>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>> </id>
>>>>>> <discriminator column="`dtype`" type="string"/>
>>>>>> <property name="name" lazy="false" insert="true"
> update="true"
>>>>>> not-null="true" unique="false" type="java.lang.String">
>>>>>> <column not-null="true" unique="false" name="`name`"/>
>>>>>> </property>
>>>>>> <property name="version" lazy="false" insert="true"
>>>> update="true"
>>>>>> not-null="true" unique="false" type="int">
>>>>>> <column not-null="true" unique="false"
> name="`version`"/>
>>>>>> </property>
>>>>>> </class>
>>>>>>
>>>>>> The solution using the hibernate.hbm.xml seems to be the better way,
>> so
>>>> I
>>>>>> think I will go on using PersistenceOptions.USE_MAPPING_FILE=true.
>>>>>> Apperently I'm doing something wrong with the version though. Am I
>>>>>> overlooking something obvious?
>>>>>>
>>>>>> cheers,
>>>>>> Björn
>>>>>>
>>>>>> ref: [Teneo] Setting Id generator from ecore file
>>>>>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>>>>>> news:es1oej$v6h$1@utils.eclipse.org...
>>>>>>> Hi Björn,
>>>>>>> In Teneo annotations are not specified in the java code but in the
>>>> model
>>>>>> (ecore or xsd) or in a
>>>>>>> separate xml.
>>>>>>> So the @Id and @GeneratedValue(strategy=GenerationType.AUTO)
>>>> annotations
>>>>>> should be specified there.
>>>>>>> If your id attributes all use an EDataType defined by yourselve
> then
>>>> you
>>>>>> can add the annotations to
>>>>>>> the EDataType (so one place instead of at each attribute).
>>>>>>>
>>>>>>> See also here:
>>>>>>> http://www.elver.org/hibernate/ejb3_format.html
>>>>>>> http://www.elver.org/hibernate/ejb3_examples.html
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> Björn Sundin wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I have some problems getting in control of the id and version
>> columns
>>>> in
>>>>>> my
>>>>>>>> project. I need to have those attributes both in the ecore and in
> my
>>>>>> model
>>>>>>>> interface (non synthetic), in the EMF-Editor, however, they are
> not
>>>>>> visible.
>>>>>>>> I tried to set persistency annotations in the model interfaces
> with
>>>>>> little
>>>>>>>> success:
>>>>>>>>
>>>>>>>> FOR THE ID COLUMN:
>>>>>>>> /**
>>>>>>>> * @model id="true" required="true"
>>>>>>>> * @generated
>>>>>>>> */
>>>>>>>> @Id @GeneratedValue(strategy=GenerationType.AUTO)
>>>>>>>> int getId();
>>>>>>>>
>>>>>>>> /**
>>>>>>>> * @generated
>>>>>>>> */
>>>>>>>> void setId(int value);
>>>>>>>>
>>>>>>>> RESULT: org.hibernate.id.IdentifierGenerationException: ids for
> this
>>>>>> class
>>>>>>>> must be manually assigned before calling save()
>>>>>>>> (I notice that the generated PK `id` is
>> auto_increment
>>>>>> in
>>>>>>>> MySql)
>>>>>>>>
>>>>>>>> FOR THE VERSION COLUMN:
>>>>>>>> /**
>>>>>>>> * @model required="true"
>>>>>>>> * @generated
>>>>>>>> */
>>>>>>>> @Version
>>>>>>>> int getVersion();
>>>>>>>>
>>>>>>>> /**
>>>>>>>> * @generated
>>>>>>>> */
>>>>>>>> void setVersion(int value);
>>>>>>>>
>>>>>>>> RESULT: org.hibernate.MappingException: Duplicate property mapping
>> of
>>>>>>>> version found
>>>>>>>>
>>>>>>>> As I will have quite some tables in my model I'm not so keen in
>>>>>> modifying
>>>>>>>> all generated model interfaces in order to add any annotations.
> What
>> I
>>>>>>>> rather would like is to utilize the Teneo utility and so generate
>>>> EMF -
>>>>>>>> Hibernate OR mapping direct from the ecore file. In order to do
> that
>> I
>>>>>> have
>>>>>>>> added
> persistenceProperties.setProperty(PersistenceOptions.USE_MAP PING_FILE,
>>>>>>>> "true"); to the persistency property in the EditorPlugin. The
>>>> generated
>>>>>>>> hibernate.hbm.xml has anyway to be modified in the following way:
>>>>>>>>
>>>>>>>> GENERATED:
>>>>>>>> <id name="id" type="int">
>>>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>>>> </id>
>>>>>>>>
>>>>>>>> MODIFIED:
>>>>>>>> <id name="id" type="int" column="id" unsaved-value="0">
>>>>>>>> <generator class="identity"/>
>>>>>>>> </id>
>>>>>>>>
>>>>>>>> GENERATED:
>>>>>>>> <version name="version" column="version"
>>>>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>>>>> ler">
>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>> </version>
>>>>>>>>
>>>>>>>> MODIFIED:
>>>>>>>> <version name="version" column="version"
>>>>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>>>>> ler"/>
>>>>>>>>
>>>>>>>> With the above modifications my EMF-Editor is working and I have
> no
>>>>>> problems
>>>>>>>> persisting the model objects to the database. Ids are generated
> and
>>>>>> version
>>>>>>>> is incremented.
>>>>>>>>
>>>>>>>> My question is if one somehow can override the mappings being
>>>> generated
>>>>>> in
>>>>>>>> order to achieve above modified id- and version-elements?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Björn
>>>>>>>>
>>>>>>>> PS. Versions used and settings:
>>>>>>>> - Eclipse IDE 3.2.1
>>>>>>>> - EMF 2.2.2
>>>>>>>> - Teneo 0.7.5 Maintenance Build
>>>>>>>> - Hibernate 3.2
>>>>>>>> - MySql and/or Derby embedded
>>>>>>>> - Persistence properties set in the EditorPlugin:
>>>>>>>>
>>>>>>>>
> persistenceProperties.setProperty(PersistenceOptions.ID_COLU MN_NAME,
>>>>>> "id");
>> persistenceProperties.setProperty(PersistenceOptions.VERSION _COLUMN_NAME,
>>>>>>>> "version");
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>> --
>>>>>>>
>>>>>>> With Regards, Martin Taal
>>>>>>>
>>>>>>> Springsite/Elver.org
>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>> The Netherlands
>>>>>>> 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
>>>>> --
>>>>>
>>>>> With Regards, Martin Taal
>>>>>
>>>>> Springsite/Elver.org
>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>> The Netherlands
>>>>> 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
>>>>
>>>
>>> --
>>>
>>> With Regards, Martin Taal
>>>
>>> Springsite/Elver.org
>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>> The Netherlands
>>> 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
>>
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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] Possible to Override Generation of hibernate.hbm.xml? [message #603009 is a reply to message #73116] |
Wed, 28 February 2007 17:21 |
Eclipse User |
|
|
|
Originally posted by: bsu.bergauer.ch
Yes, I beleve I do... Both packages are in same ecore model and thus I have
only one genmodel. When I regenerate the model code both packages are
created. What I noticed is that the Factory and Package classes where the
model code is located gets the prefix of the package direct above. This is
not the case for the Factory and Package classes where only the eDataTypes
are located. Here the generated files are named without prefix
(Factory.java, Package.java resp. in impl FactoryImpl.java,
PackageImpl.java ). In FactoryImpl.java I also get a duplicated method
getPackage() (though static and marked @deprecated) every time I regenerate.
Greetings,
Bj
|
|
|
Re: [Teneo] Possible to Override Generation of hibernate.hbm.xml? [message #603020 is a reply to message #73169] |
Wed, 28 February 2007 19:27 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Okay, to be honest I do not know exactly if something is out-of-the-ordinary here. Maybe, Ed, do you
know?
gr. Martin
Björn Sundin wrote:
> Yes, I beleve I do... Both packages are in same ecore model and thus I have
> only one genmodel. When I regenerate the model code both packages are
> created. What I noticed is that the Factory and Package classes where the
> model code is located gets the prefix of the package direct above. This is
> not the case for the Factory and Package classes where only the eDataTypes
> are located. Here the generated files are named without prefix
> (Factory.java, Package.java resp. in impl FactoryImpl.java,
> PackageImpl.java ). In FactoryImpl.java I also get a duplicated method
> getPackage() (though static and marked @deprecated) every time I regenerate.
>
> Greetings,
> Björn
>
>
> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
> news:es4cpk$8vf$1@utils.eclipse.org...
>> No problem. Actually, I am not sure why you would need to move the
> edatatype to the same package.
>> When you said regenerate, did you regenerate the model code of both
> epackages?
>> gr. Martin
>>
>> Björn Sundin wrote:
>>> I just moved the eDataTypes to the same package as the model code and
> the
>>> autogenerated mapping works! I guess I'm lucky not sitting in your
> office
>>> right now...
>>>
>>> Greetings,
>>> Björn
>>>
>>>
>>> "Björn Sundin" <bsu@bergauer.ch> schrieb im Newsbeitrag
>>> news:es49s3$403$1@utils.eclipse.org...
>>>> Hi Martin,
>>>>
>>>> I use to regenerate all code (model, edit, editor) every time I make a
>>>> change to the ecore model. Now I even deleted the model code and
> generated
>>>> it from scratch. I'm sorry to say that it still is a problem with the
>>>> autogenerated mapping. It's exactly the same as in my prevoious post.
>>>> Could it be a problem that the eDataTypes are in another package than
> the
>>>> model code?
>>>>
>>>> Greetings,
>>>> Björn
>>>>
>>>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>>>> news:es48o3$ak$1@utils.eclipse.org...
>>>>> Hi Björn,
>>>>> What could explain the difference is that after a change in the ecore
>>>> (like adding an annotation)
>>>>> you have to regenerate the java model code to get the change in ecore
> to
>>>> the runtime layer.
>>>>> For the automatic mapping the ecore model is not read from the ecore
>>> file
>>>> but from the in-memory
>>>>> ecore representation. This in-memory representation is created by the
>>>> generated PackageImpl and can
>>>>> be out of sync with the ecore file.
>>>>> So can you try again (if you like) after regenerating the java model
>>> code?
>>>>> gr. Martin
>>>>>
>>>>> Björn Sundin wrote:
>>>>>> Hi Martin,
>>>>>>
>>>>>> Well the out-commented element is an artifact from my first try.
> Oddly
>>>>>> enough I think it was about how you meant it should look like :
>>>>>>
>>>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
>>>>>> instanceClassName="int">
>>>>>> <eAnnotations source="teneo.jpa">
>>>>>> <details key="appinfo" value="@Id
>>>>>> @GeneratedValue(strategy="AUTO")"/>
>>>>>> </eAnnotations>
>>>>>> </eClassifiers>
>>>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
>>>>>> instanceClassName="int">
>>>>>> <eAnnotations source="teneo.jpa">
>>>>>> <details key="appinfo" value="@Version"/>
>>>>>> </eAnnotations>
>>>>>> </eClassifiers>
>>>>>>
>>>>>> It didn't work with the automatic mapping (and I think I missed out
>>>> testing
>>>>>> it with the hibernate.hbm.xml) so I abandoned it and found other
>>>> suggestions
>>>>>> in the newsgroup extending teneo.jpa to teneo.jpa/Id... :o/
>>>>>>
>>>>>> After having reimplemented the eDataTypes, as above, both Id and
>>> Version
>>>>>> works well using the hibernate.hbm.xml! :) The automatic mapping,
>>>> though,
>>>>>> still doesn't recognize the annotations:
>>>>>>
>>>>>> hibernate.hbm.xml:
>>>>>>
>>>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>>>> discriminator-value="StatusType" table="`statustype`">
>>>>>> <meta attribute="eclassName">StatusType</meta>
>>>>>> <meta
>>>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>>>> /meta>
>>>>>> <id name="id" type="int">
>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>> <generator class="native"/>
>>>>>> </id>
>>>>>> <discriminator column="`dtype`" type="string"/>
>>>>>> <version name="version" type="int">
>>>>>> <column not-null="true" unique="false" name="`version`"/>
>>>>>> </version>
>>>>>> <property name="name" lazy="false" insert="true"
> update="true"
>>>>>> not-null="true" unique="false" type="java.lang.String">
>>>>>> <column not-null="true" unique="false" name="`name`"/>
>>>>>> </property>
>>>>>> </class>
>>>>>>
>>>>>> automatic mapping:
>>>>>>
>>>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>>>> discriminator-value="StatusType" table="`statustype`">
>>>>>> <meta attribute="eclassName">StatusType</meta>
>>>>>> <meta
>>>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>>>> /meta>
>>>>>> <id name="id" type="int">
>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>> </id>
>>>>>> <discriminator column="`dtype`" type="string"/>
>>>>>> <property name="name" lazy="false" insert="true"
> update="true"
>>>>>> not-null="true" unique="false" type="java.lang.String">
>>>>>> <column not-null="true" unique="false" name="`name`"/>
>>>>>> </property>
>>>>>> <property name="version" lazy="false" insert="true"
>>>> update="true"
>>>>>> not-null="true" unique="false" type="int">
>>>>>> <column not-null="true" unique="false" name="`version`"/>
>>>>>> </property>
>>>>>> </class>
>>>>>>
>>>>>> Could it have to do with the version of Teneo that I use? I'm
>>> currently
>>>>>> using Teneo 0.7.5 Maintenance Build. I did download version 0.8.0 but
>>>> had to
>>>>>> deactivate it as I'm using Eclipse 3.2.1.
>>>>>>
>>>>>> Greetings,
>>>>>> Björn
>>>>>>
>>>>>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>>>>>> news:es42sn$jr2$1@utils.eclipse.org...
>>>>>>> Hi Björn,
>>>>>>> Afaics the <details...> tag in the eAnnotations of the AmsetVersion
>>>>>> EDataType is commented out using
>>>>>>> xml comment characters (<!-- and -->). Could that be a reason?
>>>>>>>
>>>>>>> Also the id annotation does not seem to be completely correct. The
>>>> source
>>>>>> should teneo.jpa and then
>>>>>>> the value should also contain the @Id annotation.
>>>>>>>
>>>>>>> There should be no difference in generating the mapping file
> manually
>>>> and
>>>>>> then use that or the
>>>>>>> automatic mapping in-memory (it also generates an in-memory
> mapping).
>>> I
>>>>>> would suggest to use the
>>>>>>> automatic in-memory mapping until you want to do extensive manual
>>>> changes
>>>>>> (for example to map to a
>>>>>>> current db schema).
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> Björn Sundin wrote:
>>>>>>>> Hi Martin,
>>>>>>>>
>>>>>>>> Thanks for your reply. It definitely brought me on the right path
>>> and
>>>> so
>>>>>> I
>>>>>>>> decided to define my own id and version datatypes in ecore:
>>>>>>>>
>>>>>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetId"
>>>>>>>> instanceClassName="int">
>>>>>>>> <eAnnotations source="teneo.jpa/Id">
>>>>>>>> <details key="appinfo"
>>>>>>>> value="@GeneratedValue(strategy="AUTO")"/ >
>>>>>>>> </eAnnotations>
>>>>>>>> </eClassifiers>
>>>>>>>> <eClassifiers xsi:type="ecore:EDataType" name="AmsetVersion"
>>>>>>>> instanceClassName="int">
>>>>>>>> <eAnnotations source="teneo.jpa/Version">
>>>>>>>> <!-- <details key="appinfo" value="@Version"/> -->
>>>>>>>> </eAnnotations>
>>>>>>>> </eClassifiers>
>>>>>>>>
>>>>>>>> Those two datatypes are referenced in i.e StatusType:
>>>>>>>>
>>>>>>>> <eClassifiers xsi:type="ecore:EClass" name="StatusType">
>>>>>>>> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="name"
>>>>>>>> lowerBound="1"
>>>>>>>> eType="ecore:EDataType
>>>>>>>> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
>>>>>>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
>>>>>>>> lowerBound="1"
>>>>>>>> eType="#//bergauer/rcp/amset/model/datatypes/AmsetId"
>>>>>>>> iD="true"/>
>>>>>>>> <eStructuralFeatures xsi:type="ecore:EAttribute"
>>>> name="version"
>>>>>>>> lowerBound="1"
>>>>>>>>
>>>> eType="#//bergauer/rcp/amset/model/datatypes/AmsetVersion"/ >
>>>>>>>> </eClassifiers>
>>>>>>>>
>>>>>>>>
>>>>>>>> I now have the following results:
>>>>>>>>
>>>>>>>> PersistenceOptions.USE_MAPPING_FILE set true:
>>>>>>>> - The hibernate.hbm.xml I now have the id-element with
>>> generator,
>>>>>>>> non-synthetic. Id is generated as expected
>>>>>>>> - The version attribute that I define in ecore isn't recognized
>>>> with
>>>>>>>> annotation yet. In the hibernate.hbm.xml I have one version-element
>>>>>> (with
>>>>>>>> synthetic set true) and in the database I get two fields e_version
>>> and
>>>>>>>> version. The PersistenceOptions.ALWAYS_VERSION is set false in the
>>>>>>>> EditorPlugin.
>>>>>>>>
>>>>>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>>>>>> discriminator-value="StatusType" table="`statustype`">
>>>>>>>> <meta attribute="eclassName">StatusType</meta>
>>>>>>>> <meta
>>>>>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>>>>>> /meta>
>>>>>>>> <id name="id" type="int">
>>>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>>>> <generator class="native"/>
>>>>>>>> </id>
>>>>>>>> <discriminator column="`dtype`" type="string"/>
>>>>>>>> <version name="e_version" column="e_version"
>>>>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>>>>> ler">
>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>> </version>
>>>>>>>> <property name="name" lazy="false" insert="true"
>>> update="true"
>>>>>>>> not-null="true" unique="false" type="java.lang.String">
>>>>>>>> <column not-null="true" unique="false" name="`name`"/>
>>>>>>>> </property>
>>>>>>>> </class>
>>>>>>>>
>>>>>>>> PersistenceOptions.USE_MAPPING_FILE set false:
>>>>>>>> Neither id nor version work is reqognized. In the in-menory
>>>> mapping
>>>>>> I
>>>>>>>> have no generator element for the id-element:
>>>>>>>>
>>>>>>>> <class entity-name="StatusType" abstract="false" lazy="false"
>>>>>>>> discriminator-value="StatusType" table="`statustype`">
>>>>>>>> <meta attribute="eclassName">StatusType</meta>
>>>>>>>> <meta
>>>>>>>>
> attribute="epackage">ch.bergauer.rcp.amset.model.systemattributes.amset.xmi <
>>>>>>>> /meta>
>>>>>>>> <id name="id" type="int">
>>>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>>>> </id>
>>>>>>>> <discriminator column="`dtype`" type="string"/>
>>>>>>>> <property name="name" lazy="false" insert="true"
>>> update="true"
>>>>>>>> not-null="true" unique="false" type="java.lang.String">
>>>>>>>> <column not-null="true" unique="false" name="`name`"/>
>>>>>>>> </property>
>>>>>>>> <property name="version" lazy="false" insert="true"
>>>>>> update="true"
>>>>>>>> not-null="true" unique="false" type="int">
>>>>>>>> <column not-null="true" unique="false"
>>> name="`version`"/>
>>>>>>>> </property>
>>>>>>>> </class>
>>>>>>>>
>>>>>>>> The solution using the hibernate.hbm.xml seems to be the better
> way,
>>>> so
>>>>>> I
>>>>>>>> think I will go on using PersistenceOptions.USE_MAPPING_FILE=true.
>>>>>>>> Apperently I'm doing something wrong with the version though. Am I
>>>>>>>> overlooking something obvious?
>>>>>>>>
>>>>>>>> cheers,
>>>>>>>> Björn
>>>>>>>>
>>>>>>>> ref: [Teneo] Setting Id generator from ecore file
>>>>>>>> "Martin Taal" <mtaal@elver.org> schrieb im Newsbeitrag
>>>>>>>> news:es1oej$v6h$1@utils.eclipse.org...
>>>>>>>>> Hi Björn,
>>>>>>>>> In Teneo annotations are not specified in the java code but in the
>>>>>> model
>>>>>>>> (ecore or xsd) or in a
>>>>>>>>> separate xml.
>>>>>>>>> So the @Id and @GeneratedValue(strategy=GenerationType.AUTO)
>>>>>> annotations
>>>>>>>> should be specified there.
>>>>>>>>> If your id attributes all use an EDataType defined by yourselve
>>> then
>>>>>> you
>>>>>>>> can add the annotations to
>>>>>>>>> the EDataType (so one place instead of at each attribute).
>>>>>>>>>
>>>>>>>>> See also here:
>>>>>>>>> http://www.elver.org/hibernate/ejb3_format.html
>>>>>>>>> http://www.elver.org/hibernate/ejb3_examples.html
>>>>>>>>>
>>>>>>>>> gr. Martin
>>>>>>>>>
>>>>>>>>> Björn Sundin wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I have some problems getting in control of the id and version
>>>> columns
>>>>>> in
>>>>>>>> my
>>>>>>>>>> project. I need to have those attributes both in the ecore and in
>>> my
>>>>>>>> model
>>>>>>>>>> interface (non synthetic), in the EMF-Editor, however, they are
>>> not
>>>>>>>> visible.
>>>>>>>>>> I tried to set persistency annotations in the model interfaces
>>> with
>>>>>>>> little
>>>>>>>>>> success:
>>>>>>>>>>
>>>>>>>>>> FOR THE ID COLUMN:
>>>>>>>>>> /**
>>>>>>>>>> * @model id="true" required="true"
>>>>>>>>>> * @generated
>>>>>>>>>> */
>>>>>>>>>> @Id @GeneratedValue(strategy=GenerationType.AUTO)
>>>>>>>>>> int getId();
>>>>>>>>>>
>>>>>>>>>> /**
>>>>>>>>>> * @generated
>>>>>>>>>> */
>>>>>>>>>> void setId(int value);
>>>>>>>>>>
>>>>>>>>>> RESULT: org.hibernate.id.IdentifierGenerationException: ids for
>>> this
>>>>>>>> class
>>>>>>>>>> must be manually assigned before calling save()
>>>>>>>>>> (I notice that the generated PK `id` is
>>>> auto_increment
>>>>>>>> in
>>>>>>>>>> MySql)
>>>>>>>>>>
>>>>>>>>>> FOR THE VERSION COLUMN:
>>>>>>>>>> /**
>>>>>>>>>> * @model required="true"
>>>>>>>>>> * @generated
>>>>>>>>>> */
>>>>>>>>>> @Version
>>>>>>>>>> int getVersion();
>>>>>>>>>>
>>>>>>>>>> /**
>>>>>>>>>> * @generated
>>>>>>>>>> */
>>>>>>>>>> void setVersion(int value);
>>>>>>>>>>
>>>>>>>>>> RESULT: org.hibernate.MappingException: Duplicate property
> mapping
>>>> of
>>>>>>>>>> version found
>>>>>>>>>>
>>>>>>>>>> As I will have quite some tables in my model I'm not so keen in
>>>>>>>> modifying
>>>>>>>>>> all generated model interfaces in order to add any annotations.
>>> What
>>>> I
>>>>>>>>>> rather would like is to utilize the Teneo utility and so generate
>>>>>> EMF -
>>>>>>>>>> Hibernate OR mapping direct from the ecore file. In order to do
>>> that
>>>> I
>>>>>>>> have
>>>>>>>>>> added
>>> persistenceProperties.setProperty(PersistenceOptions.USE_MAP PING_FILE,
>>>>>>>>>> "true"); to the persistency property in the EditorPlugin. The
>>>>>> generated
>>>>>>>>>> hibernate.hbm.xml has anyway to be modified in the following way:
>>>>>>>>>>
>>>>>>>>>> GENERATED:
>>>>>>>>>> <id name="id" type="int">
>>>>>>>>>> <column not-null="true" unique="false" name="`id`"/>
>>>>>>>>>> </id>
>>>>>>>>>>
>>>>>>>>>> MODIFIED:
>>>>>>>>>> <id name="id" type="int" column="id" unsaved-value="0">
>>>>>>>>>> <generator class="identity"/>
>>>>>>>>>> </id>
>>>>>>>>>>
>>>>>>>>>> GENERATED:
>>>>>>>>>> <version name="version" column="version"
>>>>>>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>>>>>>> ler">
>>>>>>>>>> <meta attribute="syntheticVersion">true</meta>
>>>>>>>>>> </version>
>>>>>>>>>>
>>>>>>>>>> MODIFIED:
>>>>>>>>>> <version name="version" column="version"
>>>>>>>>>>
> access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHand
>>>>>>>>>> ler"/>
>>>>>>>>>>
>>>>>>>>>> With the above modifications my EMF-Editor is working and I have
>>> no
>>>>>>>> problems
>>>>>>>>>> persisting the model objects to the database. Ids are generated
>>> and
>>>>>>>> version
>>>>>>>>>> is incremented.
>>>>>>>>>>
>>>>>>>>>> My question is if one somehow can override the mappings being
>>>>>> generated
>>>>>>>> in
>>>>>>>>>> order to achieve above modified id- and version-elements?
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>> Björn
>>>>>>>>>>
>>>>>>>>>> PS. Versions used and settings:
>>>>>>>>>> - Eclipse IDE 3.2.1
>>>>>>>>>> - EMF 2.2.2
>>>>>>>>>> - Teneo 0.7.5 Maintenance Build
>>>>>>>>>> - Hibernate 3.2
>>>>>>>>>> - MySql and/or Derby embedded
>>>>>>>>>> - Persistence properties set in the EditorPlugin:
>>>>>>>>>>
>>>>>>>>>>
>>> persistenceProperties.setProperty(PersistenceOptions.ID_COLU MN_NAME,
>>>>>>>> "id");
> persistenceProperties.setProperty(PersistenceOptions.VERSION _COLUMN_NAME,
>>>>>>>>>> "version");
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>> --
>>>>>>>>>
>>>>>>>>> With Regards, Martin Taal
>>>>>>>>>
>>>>>>>>> Springsite/Elver.org
>>>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>>>> The Netherlands
>>>>>>>>> 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
>>>>>>> --
>>>>>>>
>>>>>>> With Regards, Martin Taal
>>>>>>>
>>>>>>> Springsite/Elver.org
>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>> The Netherlands
>>>>>>> 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
>>>>> --
>>>>>
>>>>> With Regards, Martin Taal
>>>>>
>>>>> Springsite/Elver.org
>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>> The Netherlands
>>>>> 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
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
| |
Goto Forum:
Current Time: Thu Sep 26 08:24:11 GMT 2024
Powered by FUDForum. Page generated in 0.05821 seconds
|