Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Switch to DB2 and not getting identity columns
[Teneo] Switch to DB2 and not getting identity columns [message #124960] Mon, 02 June 2008 16:18 Go to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I was successfully generating a schema on MySQL and getting the auto
increment on the id primary key column. I switched to DB2 dialect and if
I leave the primary key as e_id I do get IDENTITY columns but when I use
id in the model with the annotation I do not get them. Am I missing
something?

Here are my properties

props.setProperty(Environment.DRIVER, "com.ibm.db2.jcc.DB2Driver");
props.setProperty(Environment.USER, "Administrator");
props.setProperty(Environment.PASS, "e*****");
props.setProperty(Environment.URL, "jdbc:db2://192.168.0.3:50000/"
+ dbName);
props.setProperty(Environment.DIALECT,
org.hibernate.dialect.DB2Dialect.class.getName());
props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH ,
"30");
props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
"true");
props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME ,
"id");

props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY, "simple");
props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
props.setProperty(PersistenceOptions.DEFAULT_TEMPORAL_VALUE,
"DATE");

props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING, "true");
props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG,
"true");
props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
"JOINED");

Here is a sample of the XSD

<xsd:complexType name="Tranche">
<xsd:sequence minOccurs="0" maxOccurs="1">
<xsd:element ref="gensec:source" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute
default="http://www.mddl.org/mddl/scheme/trancheIDType.xml"
name="scheme" use="optional" />
<xsd:attribute name="nameRef" type="xsd:anyURI" />
<xsd:attribute default="valid" name="validity"
type="gensec:QualityEnumeration" use="optional" />
<xsd:attribute name="rank" type="xsd:int" />
</xsd:complexType>
<xsd:element name="tranche" type="gensec:Tranche" />

Thx,

David
Re: [Teneo] Switch to DB2 and not getting identity columns [message #124973 is a reply to message #124960] Mon, 02 June 2008 17:09 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Opps, I checked the MySQL and it did not have the auto increment set
either. So when you replace e_id as the primary key which option is
required to get these columns as auto increment?

Thx.

David
david wrote:
> Hi,
>
> I was successfully generating a schema on MySQL and getting the auto
> increment on the id primary key column. I switched to DB2 dialect and if
> I leave the primary key as e_id I do get IDENTITY columns but when I use
> id in the model with the annotation I do not get them. Am I missing
> something?
>
> Here are my properties
>
> props.setProperty(Environment.DRIVER, "com.ibm.db2.jcc.DB2Driver");
> props.setProperty(Environment.USER, "Administrator");
> props.setProperty(Environment.PASS, "e*****");
> props.setProperty(Environment.URL,
> "jdbc:db2://192.168.0.3:50000/" + dbName);
> props.setProperty(Environment.DIALECT,
> org.hibernate.dialect.DB2Dialect.class.getName());
> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH ,
> "30");
> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
> "true");
> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME ,
> "id");
>
> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
> "simple");
> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
> props.setProperty(PersistenceOptions.DEFAULT_TEMPORAL_VALUE,
> "DATE");
>
> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING, "true");
> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG,
> "true");
> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
> "JOINED");
>
> Here is a sample of the XSD
>
> <xsd:complexType name="Tranche">
> <xsd:sequence minOccurs="0" maxOccurs="1">
> <xsd:element ref="gensec:source" />
> </xsd:sequence>
> <xsd:attribute name="id" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> <xsd:attribute
> default="http://www.mddl.org/mddl/scheme/trancheIDType.xml"
> name="scheme" use="optional" />
> <xsd:attribute name="nameRef" type="xsd:anyURI" />
> <xsd:attribute default="valid" name="validity"
> type="gensec:QualityEnumeration" use="optional" />
> <xsd:attribute name="rank" type="xsd:int" />
> </xsd:complexType>
> <xsd:element name="tranche" type="gensec:Tranche" />
>
> Thx,
>
> David
Re: [Teneo] Switch to DB2 and not getting identity columns [message #124985 is a reply to message #124973] Mon, 02 June 2008 17:27 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
You should add the following annotations to the id-feature:
@Id
@GeneratedValue

(generated value has some more options, see the jpa spec for those).

What you can do is set this annotation in the EDataType and then use the EDataType for each of the
id efeatures.

gr. Martin

david wrote:
> Opps, I checked the MySQL and it did not have the auto increment set
> either. So when you replace e_id as the primary key which option is
> required to get these columns as auto increment?
>
> Thx.
>
> David
> david wrote:
>> Hi,
>>
>> I was successfully generating a schema on MySQL and getting the auto
>> increment on the id primary key column. I switched to DB2 dialect and
>> if I leave the primary key as e_id I do get IDENTITY columns but when
>> I use id in the model with the annotation I do not get them. Am I
>> missing something?
>>
>> Here are my properties
>>
>> props.setProperty(Environment.DRIVER,
>> "com.ibm.db2.jcc.DB2Driver");
>> props.setProperty(Environment.USER, "Administrator");
>> props.setProperty(Environment.PASS, "e*****");
>> props.setProperty(Environment.URL,
>> "jdbc:db2://192.168.0.3:50000/" + dbName);
>> props.setProperty(Environment.DIALECT,
>> org.hibernate.dialect.DB2Dialect.class.getName());
>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH ,
>> "30");
>>
>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY, "true");
>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME ,
>> "id");
>>
>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>> "simple");
>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>> props.setProperty(PersistenceOptions.DEFAULT_TEMPORAL_VALUE,
>> "DATE");
>>
>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING, "true");
>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG,
>> "true");
>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
>> "JOINED");
>>
>> Here is a sample of the XSD
>>
>> <xsd:complexType name="Tranche">
>> <xsd:sequence minOccurs="0" maxOccurs="1">
>> <xsd:element ref="gensec:source" />
>> </xsd:sequence>
>> <xsd:attribute name="id" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> <xsd:attribute
>> default="http://www.mddl.org/mddl/scheme/trancheIDType.xml"
>> name="scheme" use="optional" />
>> <xsd:attribute name="nameRef" type="xsd:anyURI" />
>> <xsd:attribute default="valid" name="validity"
>> type="gensec:QualityEnumeration" use="optional" />
>> <xsd:attribute name="rank" type="xsd:int" />
>> </xsd:complexType>
>> <xsd:element name="tranche" type="gensec:Tranche" />
>>
>> Thx,
>>
>> David


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Switch to DB2 and not getting identity columns [message #125137 is a reply to message #124973] Wed, 04 June 2008 17:35 Go to previous message
Jason Henriksen is currently offline Jason HenriksenFriend
Messages: 231
Registered: July 2009
Senior Member
I'm using XSD for my model, but this may be helpful.
Note that the sequence definition must be on the schema tag, not on the
complexType definition.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:ecore='http://www.eclipse.org/emf/2002/Ecore'
xmlns:com.vsp.consumer.model='http://model.consumer.vsp.com'
targetNamespace='http://model.consumer.vsp.com'
ecore:nsPrefix='com.vsp.consumer.model'
ecore:package='com.vsp.consumer.model'
elementFormDefault='qualified'
>

<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@SequenceGenerator(name="SEQ_XYZ3601T" sequenceName="SEQ_XYZ3601T")
</xsd:appinfo>
</xsd:annotation>

<xsd:complexType name="Consumer">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Table(
name=XYZ3601T
uniqueConstraints = {
@UniqueConstraint(columnNames={"CONSUMER_SK"})
}
)
</xsd:appinfo>
</xsd:annotation>

<xsd:sequence>

<xsd:element default="0" name="consumerSK" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Column(name=CONSUMER_SK,nullable="false",updatable=false)
@Id @GeneratedValue(strategy=SEQUENCE,generator="SEQ_XYZ3601T")
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
Re: [Teneo] Switch to DB2 and not getting identity columns [message #619150 is a reply to message #124960] Mon, 02 June 2008 17:09 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Opps, I checked the MySQL and it did not have the auto increment set
either. So when you replace e_id as the primary key which option is
required to get these columns as auto increment?

Thx.

David
david wrote:
> Hi,
>
> I was successfully generating a schema on MySQL and getting the auto
> increment on the id primary key column. I switched to DB2 dialect and if
> I leave the primary key as e_id I do get IDENTITY columns but when I use
> id in the model with the annotation I do not get them. Am I missing
> something?
>
> Here are my properties
>
> props.setProperty(Environment.DRIVER, "com.ibm.db2.jcc.DB2Driver");
> props.setProperty(Environment.USER, "Administrator");
> props.setProperty(Environment.PASS, "e*****");
> props.setProperty(Environment.URL,
> "jdbc:db2://192.168.0.3:50000/" + dbName);
> props.setProperty(Environment.DIALECT,
> org.hibernate.dialect.DB2Dialect.class.getName());
> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH ,
> "30");
> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY,
> "true");
> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME ,
> "id");
>
> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
> "simple");
> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
> props.setProperty(PersistenceOptions.DEFAULT_TEMPORAL_VALUE,
> "DATE");
>
> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING, "true");
> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG,
> "true");
> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
> "JOINED");
>
> Here is a sample of the XSD
>
> <xsd:complexType name="Tranche">
> <xsd:sequence minOccurs="0" maxOccurs="1">
> <xsd:element ref="gensec:source" />
> </xsd:sequence>
> <xsd:attribute name="id" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> <xsd:attribute
> default="http://www.mddl.org/mddl/scheme/trancheIDType.xml"
> name="scheme" use="optional" />
> <xsd:attribute name="nameRef" type="xsd:anyURI" />
> <xsd:attribute default="valid" name="validity"
> type="gensec:QualityEnumeration" use="optional" />
> <xsd:attribute name="rank" type="xsd:int" />
> </xsd:complexType>
> <xsd:element name="tranche" type="gensec:Tranche" />
>
> Thx,
>
> David
Re: [Teneo] Switch to DB2 and not getting identity columns [message #619151 is a reply to message #124973] Mon, 02 June 2008 17:27 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
You should add the following annotations to the id-feature:
@Id
@GeneratedValue

(generated value has some more options, see the jpa spec for those).

What you can do is set this annotation in the EDataType and then use the EDataType for each of the
id efeatures.

gr. Martin

david wrote:
> Opps, I checked the MySQL and it did not have the auto increment set
> either. So when you replace e_id as the primary key which option is
> required to get these columns as auto increment?
>
> Thx.
>
> David
> david wrote:
>> Hi,
>>
>> I was successfully generating a schema on MySQL and getting the auto
>> increment on the id primary key column. I switched to DB2 dialect and
>> if I leave the primary key as e_id I do get IDENTITY columns but when
>> I use id in the model with the annotation I do not get them. Am I
>> missing something?
>>
>> Here are my properties
>>
>> props.setProperty(Environment.DRIVER,
>> "com.ibm.db2.jcc.DB2Driver");
>> props.setProperty(Environment.USER, "Administrator");
>> props.setProperty(Environment.PASS, "e*****");
>> props.setProperty(Environment.URL,
>> "jdbc:db2://192.168.0.3:50000/" + dbName);
>> props.setProperty(Environment.DIALECT,
>> org.hibernate.dialect.DB2Dialect.class.getName());
>> props.setProperty(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH ,
>> "30");
>>
>> props.setProperty(PersistenceOptions.ID_FEATURE_AS_PRIMARY_K EY, "true");
>> props.setProperty(PersistenceOptions.DEFAULT_ID_FEATURE_NAME ,
>> "id");
>>
>> props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRA TEGY,
>> "simple");
>> props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
>> props.setProperty(PersistenceOptions.DEFAULT_TEMPORAL_VALUE,
>> "DATE");
>>
>> props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPP ING, "true");
>> props.setProperty(PersistenceOptions.ALWAYS_VERSION, "false");
>> props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG,
>> "true");
>> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
>> "JOINED");
>>
>> Here is a sample of the XSD
>>
>> <xsd:complexType name="Tranche">
>> <xsd:sequence minOccurs="0" maxOccurs="1">
>> <xsd:element ref="gensec:source" />
>> </xsd:sequence>
>> <xsd:attribute name="id" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> <xsd:attribute
>> default="http://www.mddl.org/mddl/scheme/trancheIDType.xml"
>> name="scheme" use="optional" />
>> <xsd:attribute name="nameRef" type="xsd:anyURI" />
>> <xsd:attribute default="valid" name="validity"
>> type="gensec:QualityEnumeration" use="optional" />
>> <xsd:attribute name="rank" type="xsd:int" />
>> </xsd:complexType>
>> <xsd:element name="tranche" type="gensec:Tranche" />
>>
>> Thx,
>>
>> David


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Switch to DB2 and not getting identity columns [message #619169 is a reply to message #124973] Wed, 04 June 2008 17:35 Go to previous message
Jason Henriksen is currently offline Jason HenriksenFriend
Messages: 231
Registered: July 2009
Senior Member
I'm using XSD for my model, but this may be helpful.
Note that the sequence definition must be on the schema tag, not on the
complexType definition.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:ecore='http://www.eclipse.org/emf/2002/Ecore'
xmlns:com.vsp.consumer.model='http://model.consumer.vsp.com'
targetNamespace='http://model.consumer.vsp.com'
ecore:nsPrefix='com.vsp.consumer.model'
ecore:package='com.vsp.consumer.model'
elementFormDefault='qualified'
>

<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@SequenceGenerator(name="SEQ_XYZ3601T" sequenceName="SEQ_XYZ3601T")
</xsd:appinfo>
</xsd:annotation>

<xsd:complexType name="Consumer">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Table(
name=XYZ3601T
uniqueConstraints = {
@UniqueConstraint(columnNames={"CONSUMER_SK"})
}
)
</xsd:appinfo>
</xsd:annotation>

<xsd:sequence>

<xsd:element default="0" name="consumerSK" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Column(name=CONSUMER_SK,nullable="false",updatable=false)
@Id @GeneratedValue(strategy=SEQUENCE,generator="SEQ_XYZ3601T")
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
Previous Topic:CDO internals
Next Topic:Classcast exception when Second Level Caching enabled
Goto Forum:
  


Current Time: Mon Apr 06 22:37:22 GMT 2020

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

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

Back to the top