Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Insert / Delete instead of Update
[Teneo] Insert / Delete instead of Update [message #129283] Tue, 02 September 2008 02:09 Go to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
I'm running the library example and looking in the hypersonic logs and
noticed some odd behaviour.

It appears that no updates are ever issued but instead rows are deleted
and inserted. Also a lot more SQL is executed than would be required.
Obviously you need to allow for some inefficiencies with a persistence
framework but it seemed excessive to me.

Running the first section of the example as follows

----
// Open a new Session and start transaction.
final Session session = sessionFactory.openSession();
session.beginTransaction();

// Create a library.
Library library = LibraryFactory.eINSTANCE.createLibrary();
library.setName("My Library");
// Make it persistent.
session.save(library);

// Create a writer...
Writer writer = LibraryFactory.eINSTANCE.createWriter();
writer.setName("JRR Tolkien");

// ...and one of his books.
Book book = LibraryFactory.eINSTANCE.createBook();
book.setAuthor(writer);
book.setPages(305);
book.setTitle("The Hobbit");
book.setCategory(BookCategory.SCIENCE_FICTION);

// Add the Writer and Book to the Library. They are made
// persistent automatically because the Library is already
// persistent.
library.getWriters().add(writer);
library.getBooks().add(book);

// Commit the changes to the database.
session.getTransaction().commit();
// Close the session. Not necessary if
session.close();

----

Results in

---
INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
Tolkien',NULL,NULL,'Library','1',-2)
INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
Hobbit',305,'ScienceFiction',1,NULL,NULL,'Library','1',-3)
DELETE FROM "writer" WHERE E_ID=1
INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
Tolkien',1,0,'Library','1',-2)
DELETE FROM "book" WHERE E_ID=1
INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
---

Where as all that was really needed was

---
INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
Tolkien',1,0,'Library','1',-2)
INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
---

Is this a Teneo or hibernate issue?
Its been a while since I did hibernate but don't remember that?
Re: [Teneo] Insert / Delete instead of Update [message #129428 is a reply to message #129283] Tue, 02 September 2008 18:42 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Andrew,
I executed the exact same code as you did and got this result:

0 [main] DEBUG org.hibernate.SQL - insert into `library` (e_version, `name`) values (?, ?)
3501 [main] DEBUG org.hibernate.SQL - insert into `writer` (e_version, `name`, econtainer_class,
e_container, e_container_featureid) values (?, ?, ?, ?, ?)
3509 [main] DEBUG org.hibernate.SQL - insert into `book` (e_version, `title`, `pages`, `category`,
econtainer_class, e_container, e_container_featureid) values (?, ?, ?, ?, ?, ?, ?)
3581 [main] DEBUG org.hibernate.SQL - update `writer` set `library_writers_e_id`=?,
`library_writers_idx`=? where e_id=?
3589 [main] DEBUG org.hibernate.SQL - update `book` set `library_books_e_id`=?,
`library_books_idx`=? where e_id=?
3590 [main] DEBUG org.hibernate.SQL - update `book` set `book_author_e_id`=?, `writer_books_idx`=?
where e_id=?

This set of statements is correct. First create the objects and then update their internal relations.

Maybe you set different options and therefore have a different mapping. Can you post the mapping?
You can get it from the datastore.getMappingXML().

Btw, support for Teneo is given on the EMF newsgroup which I cc-ed.

gr. Martin

Andrew H wrote:
> I'm running the library example and looking in the hypersonic logs and
> noticed some odd behaviour.
>
> It appears that no updates are ever issued but instead rows are deleted
> and inserted. Also a lot more SQL is executed than would be required.
> Obviously you need to allow for some inefficiencies with a persistence
> framework but it seemed excessive to me.
>
> Running the first section of the example as follows
>
> ----
> // Open a new Session and start transaction.
> final Session session = sessionFactory.openSession();
> session.beginTransaction();
>
> // Create a library.
> Library library = LibraryFactory.eINSTANCE.createLibrary();
> library.setName("My Library");
> // Make it persistent.
> session.save(library);
>
> // Create a writer...
> Writer writer = LibraryFactory.eINSTANCE.createWriter();
> writer.setName("JRR Tolkien");
>
> // ...and one of his books.
> Book book = LibraryFactory.eINSTANCE.createBook();
> book.setAuthor(writer);
> book.setPages(305);
> book.setTitle("The Hobbit");
> book.setCategory(BookCategory.SCIENCE_FICTION);
>
> // Add the Writer and Book to the Library. They are made
> // persistent automatically because the Library is already
> // persistent.
> library.getWriters().add(writer);
> library.getBooks().add(book);
>
> // Commit the changes to the database.
> session.getTransaction().commit();
> // Close the session. Not necessary if
> session.close();
>
> ----
>
> Results in
>
> ---
> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
> Tolkien',NULL,NULL,'Library','1',-2)
> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
> Hobbit',305,'ScienceFiction',1,NULL,NULL,'Library','1',-3)
> DELETE FROM "writer" WHERE E_ID=1
> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
> Tolkien',1,0,'Library','1',-2)
> DELETE FROM "book" WHERE E_ID=1
> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
> ---
>
> Where as all that was really needed was
>
> ---
> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
> Tolkien',1,0,'Library','1',-2)
> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
> ---
>
> Is this a Teneo or hibernate issue? Its been a while since I did
> hibernate but don't remember that?
>
>


--

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] Insert / Delete instead of Update [message #129467 is a reply to message #129428] Wed, 03 September 2008 06:31 Go to previous messageGo to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
OK that's far more sensible. I don't believe I set any options other than
those in the tutorial.

Either way, I'm only evaluating for now and based on what you have shown
here I am happy with how it was handled, so that's good enough for me for
now.

BTW I assume there is a way to separate the generate schema steps from the
running of the application? We would manage the schema evolution carefully
and not want this to happen when we run the app. Any pointers there?

Thanks for your help


Martin Taal wrote:

> Hi Andrew,
> I executed the exact same code as you did and got this result:

> 0 [main] DEBUG org.hibernate.SQL - insert into `library` (e_version,
`name`) values (?, ?)
> 3501 [main] DEBUG org.hibernate.SQL - insert into `writer` (e_version,
`name`, econtainer_class,
> e_container, e_container_featureid) values (?, ?, ?, ?, ?)
> 3509 [main] DEBUG org.hibernate.SQL - insert into `book` (e_version,
`title`, `pages`, `category`,
> econtainer_class, e_container, e_container_featureid) values (?, ?, ?, ?, ?,
?, ?)
> 3581 [main] DEBUG org.hibernate.SQL - update `writer` set
`library_writers_e_id`=?,
> `library_writers_idx`=? where e_id=?
> 3589 [main] DEBUG org.hibernate.SQL - update `book` set
`library_books_e_id`=?,
> `library_books_idx`=? where e_id=?
> 3590 [main] DEBUG org.hibernate.SQL - update `book` set
`book_author_e_id`=?, `writer_books_idx`=?
> where e_id=?

> This set of statements is correct. First create the objects and then update
their internal relations.

> Maybe you set different options and therefore have a different mapping. Can
you post the mapping?
> You can get it from the datastore.getMappingXML().

> Btw, support for Teneo is given on the EMF newsgroup which I cc-ed.

> gr. Martin

> Andrew H wrote:
>> I'm running the library example and looking in the hypersonic logs and
>> noticed some odd behaviour.
>>
>> It appears that no updates are ever issued but instead rows are deleted
>> and inserted. Also a lot more SQL is executed than would be required.
>> Obviously you need to allow for some inefficiencies with a persistence
>> framework but it seemed excessive to me.
>>
>> Running the first section of the example as follows
>>
>> ----
>> // Open a new Session and start transaction.
>> final Session session = sessionFactory.openSession();
>> session.beginTransaction();
>>
>> // Create a library.
>> Library library = LibraryFactory.eINSTANCE.createLibrary();
>> library.setName("My Library");
>> // Make it persistent.
>> session.save(library);
>>
>> // Create a writer...
>> Writer writer = LibraryFactory.eINSTANCE.createWriter();
>> writer.setName("JRR Tolkien");
>>
>> // ...and one of his books.
>> Book book = LibraryFactory.eINSTANCE.createBook();
>> book.setAuthor(writer);
>> book.setPages(305);
>> book.setTitle("The Hobbit");
>> book.setCategory(BookCategory.SCIENCE_FICTION);
>>
>> // Add the Writer and Book to the Library. They are made
>> // persistent automatically because the Library is already
>> // persistent.
>> library.getWriters().add(writer);
>> library.getBooks().add(book);
>>
>> // Commit the changes to the database.
>> session.getTransaction().commit();
>> // Close the session. Not necessary if
>> session.close();
>>
>> ----
>>
>> Results in
>>
>> ---
>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>> Tolkien',NULL,NULL,'Library','1',-2)
>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>> Hobbit',305,'ScienceFiction',1,NULL,NULL,'Library','1',-3)
>> DELETE FROM "writer" WHERE E_ID=1
>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>> Tolkien',1,0,'Library','1',-2)
>> DELETE FROM "book" WHERE E_ID=1
>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>> ---
>>
>> Where as all that was really needed was
>>
>> ---
>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>> Tolkien',1,0,'Library','1',-2)
>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>> ---
>>
>> Is this a Teneo or hibernate issue? Its been a while since I did
>> hibernate but don't remember that?
>>
>>
Re: [Teneo] Insert / Delete instead of Update [message #129505 is a reply to message #129467] Wed, 03 September 2008 14:03 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Andrew,
You can generate a mapping separately (call HbHelper.generateMapping) and store it a
hibernate.hbm.xml file. Then you can tell Teneo to use a mapping file (set the option
USE_MAPPING_FILE to "true"), if your mapping file is not called hibernate.hbm.xml or is not located
in the packages of the model then you can set the mapping file path through the option
MAPPING_FILE_PATH.

The update of the database schema is controlled through hibernate and its option
hibernate.hbm2ddl.auto (see the hibernate manual for more information). So even if Teneo generates a
new mapping, the database schema is only updated if this option is set to create or update. But
having a separate mapping file is always the safest approach.

gr. Martin

Andrew H wrote:
> OK that's far more sensible. I don't believe I set any options other
> than those in the tutorial.
>
> Either way, I'm only evaluating for now and based on what you have shown
> here I am happy with how it was handled, so that's good enough for me
> for now.
>
> BTW I assume there is a way to separate the generate schema steps from
> the running of the application? We would manage the schema evolution
> carefully and not want this to happen when we run the app. Any pointers
> there?
>
> Thanks for your help
>
>
> Martin Taal wrote:
>
>> Hi Andrew,
>> I executed the exact same code as you did and got this result:
>
>> 0 [main] DEBUG org.hibernate.SQL - insert into `library` (e_version,
> `name`) values (?, ?)
>> 3501 [main] DEBUG org.hibernate.SQL - insert into `writer` (e_version,
> `name`, econtainer_class,
>> e_container, e_container_featureid) values (?, ?, ?, ?, ?)
>> 3509 [main] DEBUG org.hibernate.SQL - insert into `book` (e_version,
> `title`, `pages`, `category`,
>> econtainer_class, e_container, e_container_featureid) values (?, ?, ?,
>> ?, ?,
> ?, ?)
>> 3581 [main] DEBUG org.hibernate.SQL - update `writer` set
> `library_writers_e_id`=?,
>> `library_writers_idx`=? where e_id=?
>> 3589 [main] DEBUG org.hibernate.SQL - update `book` set
> `library_books_e_id`=?,
>> `library_books_idx`=? where e_id=?
>> 3590 [main] DEBUG org.hibernate.SQL - update `book` set
> `book_author_e_id`=?, `writer_books_idx`=?
>> where e_id=?
>
>> This set of statements is correct. First create the objects and then
>> update
> their internal relations.
>
>> Maybe you set different options and therefore have a different
>> mapping. Can
> you post the mapping?
>> You can get it from the datastore.getMappingXML().
>
>> Btw, support for Teneo is given on the EMF newsgroup which I cc-ed.
>
>> gr. Martin
>
>> Andrew H wrote:
>>> I'm running the library example and looking in the hypersonic logs
>>> and noticed some odd behaviour.
>>>
>>> It appears that no updates are ever issued but instead rows are
>>> deleted and inserted. Also a lot more SQL is executed than would be
>>> required. Obviously you need to allow for some inefficiencies with a
>>> persistence framework but it seemed excessive to me.
>>>
>>> Running the first section of the example as follows
>>>
>>> ----
>>> // Open a new Session and start transaction.
>>> final Session session = sessionFactory.openSession();
>>> session.beginTransaction();
>>>
>>> // Create a library.
>>> Library library = LibraryFactory.eINSTANCE.createLibrary();
>>> library.setName("My Library");
>>> // Make it persistent.
>>> session.save(library);
>>>
>>> // Create a writer...
>>> Writer writer = LibraryFactory.eINSTANCE.createWriter();
>>> writer.setName("JRR Tolkien");
>>>
>>> // ...and one of his books.
>>> Book book = LibraryFactory.eINSTANCE.createBook();
>>> book.setAuthor(writer);
>>> book.setPages(305);
>>> book.setTitle("The Hobbit");
>>> book.setCategory(BookCategory.SCIENCE_FICTION);
>>>
>>> // Add the Writer and Book to the Library. They are made
>>> // persistent automatically because the Library is already
>>> // persistent.
>>> library.getWriters().add(writer);
>>> library.getBooks().add(book);
>>>
>>> // Commit the changes to the database.
>>> session.getTransaction().commit();
>>> // Close the session. Not necessary if
>>> session.close();
>>>
>>> ----
>>>
>>> Results in
>>>
>>> ---
>>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>> Tolkien',NULL,NULL,'Library','1',-2)
>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>> Hobbit',305,'ScienceFiction',1,NULL,NULL,'Library','1',-3)
>>> DELETE FROM "writer" WHERE E_ID=1
>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>> Tolkien',1,0,'Library','1',-2)
>>> DELETE FROM "book" WHERE E_ID=1
>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>>> ---
>>>
>>> Where as all that was really needed was
>>>
>>> ---
>>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>> Tolkien',1,0,'Library','1',-2)
>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>>> ---
>>>
>>> Is this a Teneo or hibernate issue? Its been a while since I did
>>> hibernate but don't remember that?
>>>
>>>
>
>
>
>


--

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] Insert / Delete instead of Update [message #129551 is a reply to message #129505] Fri, 05 September 2008 07:32 Go to previous messageGo to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
Thanks Martin

Martin Taal wrote:

> Hi Andrew,
> You can generate a mapping separately (call HbHelper.generateMapping) and
store it a
> hibernate.hbm.xml file. Then you can tell Teneo to use a mapping file (set
the option
> USE_MAPPING_FILE to "true"), if your mapping file is not called
hibernate.hbm.xml or is not located
> in the packages of the model then you can set the mapping file path through
the option
> MAPPING_FILE_PATH.

> The update of the database schema is controlled through hibernate and its
option
> hibernate.hbm2ddl.auto (see the hibernate manual for more information). So
even if Teneo generates a
> new mapping, the database schema is only updated if this option is set to
create or update. But
> having a separate mapping file is always the safest approach.

> gr. Martin

> Andrew H wrote:
>> OK that's far more sensible. I don't believe I set any options other
>> than those in the tutorial.
>>
>> Either way, I'm only evaluating for now and based on what you have shown
>> here I am happy with how it was handled, so that's good enough for me
>> for now.
>>
>> BTW I assume there is a way to separate the generate schema steps from
>> the running of the application? We would manage the schema evolution
>> carefully and not want this to happen when we run the app. Any pointers
>> there?
>>
>> Thanks for your help
>>
>>
>> Martin Taal wrote:
>>
>>> Hi Andrew,
>>> I executed the exact same code as you did and got this result:
>>
>>> 0 [main] DEBUG org.hibernate.SQL - insert into `library` (e_version,
>> `name`) values (?, ?)
>>> 3501 [main] DEBUG org.hibernate.SQL - insert into `writer` (e_version,
>> `name`, econtainer_class,
>>> e_container, e_container_featureid) values (?, ?, ?, ?, ?)
>>> 3509 [main] DEBUG org.hibernate.SQL - insert into `book` (e_version,
>> `title`, `pages`, `category`,
>>> econtainer_class, e_container, e_container_featureid) values (?, ?, ?,
>>> ?, ?,
>> ?, ?)
>>> 3581 [main] DEBUG org.hibernate.SQL - update `writer` set
>> `library_writers_e_id`=?,
>>> `library_writers_idx`=? where e_id=?
>>> 3589 [main] DEBUG org.hibernate.SQL - update `book` set
>> `library_books_e_id`=?,
>>> `library_books_idx`=? where e_id=?
>>> 3590 [main] DEBUG org.hibernate.SQL - update `book` set
>> `book_author_e_id`=?, `writer_books_idx`=?
>>> where e_id=?
>>
>>> This set of statements is correct. First create the objects and then
>>> update
>> their internal relations.
>>
>>> Maybe you set different options and therefore have a different
>>> mapping. Can
>> you post the mapping?
>>> You can get it from the datastore.getMappingXML().
>>
>>> Btw, support for Teneo is given on the EMF newsgroup which I cc-ed.
>>
>>> gr. Martin
>>
>>> Andrew H wrote:
>>>> I'm running the library example and looking in the hypersonic logs
>>>> and noticed some odd behaviour.
>>>>
>>>> It appears that no updates are ever issued but instead rows are
>>>> deleted and inserted. Also a lot more SQL is executed than would be
>>>> required. Obviously you need to allow for some inefficiencies with a
>>>> persistence framework but it seemed excessive to me.
>>>>
>>>> Running the first section of the example as follows
>>>>
>>>> ----
>>>> // Open a new Session and start transaction.
>>>> final Session session = sessionFactory.openSession();
>>>> session.beginTransaction();
>>>>
>>>> // Create a library.
>>>> Library library = LibraryFactory.eINSTANCE.createLibrary();
>>>> library.setName("My Library");
>>>> // Make it persistent.
>>>> session.save(library);
>>>>
>>>> // Create a writer...
>>>> Writer writer = LibraryFactory.eINSTANCE.createWriter();
>>>> writer.setName("JRR Tolkien");
>>>>
>>>> // ...and one of his books.
>>>> Book book = LibraryFactory.eINSTANCE.createBook();
>>>> book.setAuthor(writer);
>>>> book.setPages(305);
>>>> book.setTitle("The Hobbit");
>>>> book.setCategory(BookCategory.SCIENCE_FICTION);
>>>>
>>>> // Add the Writer and Book to the Library. They are made
>>>> // persistent automatically because the Library is already
>>>> // persistent.
>>>> library.getWriters().add(writer);
>>>> library.getBooks().add(book);
>>>>
>>>> // Commit the changes to the database.
>>>> session.getTransaction().commit();
>>>> // Close the session. Not necessary if
>>>> session.close();
>>>>
>>>> ----
>>>>
>>>> Results in
>>>>
>>>> ---
>>>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>>> Tolkien',NULL,NULL,'Library','1',-2)
>>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>>> Hobbit',305,'ScienceFiction',1,NULL,NULL,'Library','1',-3)
>>>> DELETE FROM "writer" WHERE E_ID=1
>>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>>> Tolkien',1,0,'Library','1',-2)
>>>> DELETE FROM "book" WHERE E_ID=1
>>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>>>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>>>> ---
>>>>
>>>> Where as all that was really needed was
>>>>
>>>> ---
>>>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>>> Tolkien',1,0,'Library','1',-2)
>>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>>>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>>>> ---
>>>>
>>>> Is this a Teneo or hibernate issue? Its been a while since I did
>>>> hibernate but don't remember that?
>>>>
>>>>
>>
>>
>>
>>
Re: [Teneo] Insert / Delete instead of Update [message #129562 is a reply to message #129551] Fri, 05 September 2008 07:50 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
One thing I forgot to mention is that the mapping file probably needs to be explicitly flagged in
the build.properties to be copied to the output directory.

gr. Martin

Andrew H wrote:
> Thanks Martin
>
> Martin Taal wrote:
>
>> Hi Andrew,
>> You can generate a mapping separately (call HbHelper.generateMapping) and
> store it a
>> hibernate.hbm.xml file. Then you can tell Teneo to use a mapping file
>> (set
> the option
>> USE_MAPPING_FILE to "true"), if your mapping file is not called
> hibernate.hbm.xml or is not located
>> in the packages of the model then you can set the mapping file path
>> through
> the option
>> MAPPING_FILE_PATH.
>
>> The update of the database schema is controlled through hibernate and its
> option
>> hibernate.hbm2ddl.auto (see the hibernate manual for more
>> information). So
> even if Teneo generates a
>> new mapping, the database schema is only updated if this option is set to
> create or update. But
>> having a separate mapping file is always the safest approach.
>
>> gr. Martin
>
>> Andrew H wrote:
>>> OK that's far more sensible. I don't believe I set any options other
>>> than those in the tutorial.
>>>
>>> Either way, I'm only evaluating for now and based on what you have
>>> shown here I am happy with how it was handled, so that's good enough
>>> for me for now.
>>>
>>> BTW I assume there is a way to separate the generate schema steps
>>> from the running of the application? We would manage the schema
>>> evolution carefully and not want this to happen when we run the app.
>>> Any pointers there?
>>>
>>> Thanks for your help
>>>
>>>
>>> Martin Taal wrote:
>>>
>>>> Hi Andrew,
>>>> I executed the exact same code as you did and got this result:
>>>
>>>> 0 [main] DEBUG org.hibernate.SQL - insert into `library`
>>>> (e_version,
>>> `name`) values (?, ?)
>>>> 3501 [main] DEBUG org.hibernate.SQL - insert into `writer` (e_version,
>>> `name`, econtainer_class,
>>>> e_container, e_container_featureid) values (?, ?, ?, ?, ?)
>>>> 3509 [main] DEBUG org.hibernate.SQL - insert into `book` (e_version,
>>> `title`, `pages`, `category`,
>>>> econtainer_class, e_container, e_container_featureid) values (?, ?,
>>>> ?, ?, ?,
>>> ?, ?)
>>>> 3581 [main] DEBUG org.hibernate.SQL - update `writer` set
>>> `library_writers_e_id`=?,
>>>> `library_writers_idx`=? where e_id=?
>>>> 3589 [main] DEBUG org.hibernate.SQL - update `book` set
>>> `library_books_e_id`=?,
>>>> `library_books_idx`=? where e_id=?
>>>> 3590 [main] DEBUG org.hibernate.SQL - update `book` set
>>> `book_author_e_id`=?, `writer_books_idx`=?
>>>> where e_id=?
>>>
>>>> This set of statements is correct. First create the objects and then
>>>> update
>>> their internal relations.
>>>
>>>> Maybe you set different options and therefore have a different
>>>> mapping. Can
>>> you post the mapping?
>>>> You can get it from the datastore.getMappingXML().
>>>
>>>> Btw, support for Teneo is given on the EMF newsgroup which I cc-ed.
>>>
>>>> gr. Martin
>>>
>>>> Andrew H wrote:
>>>>> I'm running the library example and looking in the hypersonic logs
>>>>> and noticed some odd behaviour.
>>>>>
>>>>> It appears that no updates are ever issued but instead rows are
>>>>> deleted and inserted. Also a lot more SQL is executed than would be
>>>>> required. Obviously you need to allow for some inefficiencies with
>>>>> a persistence framework but it seemed excessive to me.
>>>>>
>>>>> Running the first section of the example as follows
>>>>>
>>>>> ----
>>>>> // Open a new Session and start transaction.
>>>>> final Session session = sessionFactory.openSession();
>>>>> session.beginTransaction();
>>>>>
>>>>> // Create a library.
>>>>> Library library = LibraryFactory.eINSTANCE.createLibrary();
>>>>> library.setName("My Library");
>>>>> // Make it persistent.
>>>>> session.save(library);
>>>>>
>>>>> // Create a writer...
>>>>> Writer writer = LibraryFactory.eINSTANCE.createWriter();
>>>>> writer.setName("JRR Tolkien");
>>>>>
>>>>> // ...and one of his books.
>>>>> Book book = LibraryFactory.eINSTANCE.createBook();
>>>>> book.setAuthor(writer);
>>>>> book.setPages(305);
>>>>> book.setTitle("The Hobbit");
>>>>> book.setCategory(BookCategory.SCIENCE_FICTION);
>>>>>
>>>>> // Add the Writer and Book to the Library. They are made
>>>>> // persistent automatically because the Library is already
>>>>> // persistent.
>>>>> library.getWriters().add(writer);
>>>>> library.getBooks().add(book);
>>>>>
>>>>> // Commit the changes to the database.
>>>>> session.getTransaction().commit();
>>>>> // Close the session. Not necessary if
>>>>> session.close();
>>>>>
>>>>> ----
>>>>>
>>>>> Results in
>>>>>
>>>>> ---
>>>>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>>>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>>>> Tolkien',NULL,NULL,'Library','1',-2)
>>>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>>>> Hobbit',305,'ScienceFiction',1,NULL,NULL,'Library','1',-3)
>>>>> DELETE FROM "writer" WHERE E_ID=1
>>>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>>>> Tolkien',1,0,'Library','1',-2)
>>>>> DELETE FROM "book" WHERE E_ID=1
>>>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>>>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>>>>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>>>>> ---
>>>>>
>>>>> Where as all that was really needed was
>>>>>
>>>>> ---
>>>>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>>>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>>>> Tolkien',1,0,'Library','1',-2)
>>>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>>>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>>>>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>>>>> ---
>>>>>
>>>>> Is this a Teneo or hibernate issue? Its been a while since I did
>>>>> hibernate but don't remember that?
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>
>
>
>


--

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] Insert / Delete instead of Update [message #620289 is a reply to message #129283] Tue, 02 September 2008 18:42 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Andrew,
I executed the exact same code as you did and got this result:

0 [main] DEBUG org.hibernate.SQL - insert into `library` (e_version, `name`) values (?, ?)
3501 [main] DEBUG org.hibernate.SQL - insert into `writer` (e_version, `name`, econtainer_class,
e_container, e_container_featureid) values (?, ?, ?, ?, ?)
3509 [main] DEBUG org.hibernate.SQL - insert into `book` (e_version, `title`, `pages`, `category`,
econtainer_class, e_container, e_container_featureid) values (?, ?, ?, ?, ?, ?, ?)
3581 [main] DEBUG org.hibernate.SQL - update `writer` set `library_writers_e_id`=?,
`library_writers_idx`=? where e_id=?
3589 [main] DEBUG org.hibernate.SQL - update `book` set `library_books_e_id`=?,
`library_books_idx`=? where e_id=?
3590 [main] DEBUG org.hibernate.SQL - update `book` set `book_author_e_id`=?, `writer_books_idx`=?
where e_id=?

This set of statements is correct. First create the objects and then update their internal relations.

Maybe you set different options and therefore have a different mapping. Can you post the mapping?
You can get it from the datastore.getMappingXML().

Btw, support for Teneo is given on the EMF newsgroup which I cc-ed.

gr. Martin

Andrew H wrote:
> I'm running the library example and looking in the hypersonic logs and
> noticed some odd behaviour.
>
> It appears that no updates are ever issued but instead rows are deleted
> and inserted. Also a lot more SQL is executed than would be required.
> Obviously you need to allow for some inefficiencies with a persistence
> framework but it seemed excessive to me.
>
> Running the first section of the example as follows
>
> ----
> // Open a new Session and start transaction.
> final Session session = sessionFactory.openSession();
> session.beginTransaction();
>
> // Create a library.
> Library library = LibraryFactory.eINSTANCE.createLibrary();
> library.setName("My Library");
> // Make it persistent.
> session.save(library);
>
> // Create a writer...
> Writer writer = LibraryFactory.eINSTANCE.createWriter();
> writer.setName("JRR Tolkien");
>
> // ...and one of his books.
> Book book = LibraryFactory.eINSTANCE.createBook();
> book.setAuthor(writer);
> book.setPages(305);
> book.setTitle("The Hobbit");
> book.setCategory(BookCategory.SCIENCE_FICTION);
>
> // Add the Writer and Book to the Library. They are made
> // persistent automatically because the Library is already
> // persistent.
> library.getWriters().add(writer);
> library.getBooks().add(book);
>
> // Commit the changes to the database.
> session.getTransaction().commit();
> // Close the session. Not necessary if
> session.close();
>
> ----
>
> Results in
>
> ---
> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
> Tolkien',NULL,NULL,'Library','1',-2)
> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
> Hobbit',305,'ScienceFiction',1,NULL,NULL,'Library','1',-3)
> DELETE FROM "writer" WHERE E_ID=1
> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
> Tolkien',1,0,'Library','1',-2)
> DELETE FROM "book" WHERE E_ID=1
> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
> ---
>
> Where as all that was really needed was
>
> ---
> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
> Tolkien',1,0,'Library','1',-2)
> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
> ---
>
> Is this a Teneo or hibernate issue? Its been a while since I did
> hibernate but don't remember that?
>
>


--

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] Insert / Delete instead of Update [message #620292 is a reply to message #129428] Wed, 03 September 2008 06:31 Go to previous message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
OK that's far more sensible. I don't believe I set any options other than
those in the tutorial.

Either way, I'm only evaluating for now and based on what you have shown
here I am happy with how it was handled, so that's good enough for me for
now.

BTW I assume there is a way to separate the generate schema steps from the
running of the application? We would manage the schema evolution carefully
and not want this to happen when we run the app. Any pointers there?

Thanks for your help


Martin Taal wrote:

> Hi Andrew,
> I executed the exact same code as you did and got this result:

> 0 [main] DEBUG org.hibernate.SQL - insert into `library` (e_version,
`name`) values (?, ?)
> 3501 [main] DEBUG org.hibernate.SQL - insert into `writer` (e_version,
`name`, econtainer_class,
> e_container, e_container_featureid) values (?, ?, ?, ?, ?)
> 3509 [main] DEBUG org.hibernate.SQL - insert into `book` (e_version,
`title`, `pages`, `category`,
> econtainer_class, e_container, e_container_featureid) values (?, ?, ?, ?, ?,
?, ?)
> 3581 [main] DEBUG org.hibernate.SQL - update `writer` set
`library_writers_e_id`=?,
> `library_writers_idx`=? where e_id=?
> 3589 [main] DEBUG org.hibernate.SQL - update `book` set
`library_books_e_id`=?,
> `library_books_idx`=? where e_id=?
> 3590 [main] DEBUG org.hibernate.SQL - update `book` set
`book_author_e_id`=?, `writer_books_idx`=?
> where e_id=?

> This set of statements is correct. First create the objects and then update
their internal relations.

> Maybe you set different options and therefore have a different mapping. Can
you post the mapping?
> You can get it from the datastore.getMappingXML().

> Btw, support for Teneo is given on the EMF newsgroup which I cc-ed.

> gr. Martin

> Andrew H wrote:
>> I'm running the library example and looking in the hypersonic logs and
>> noticed some odd behaviour.
>>
>> It appears that no updates are ever issued but instead rows are deleted
>> and inserted. Also a lot more SQL is executed than would be required.
>> Obviously you need to allow for some inefficiencies with a persistence
>> framework but it seemed excessive to me.
>>
>> Running the first section of the example as follows
>>
>> ----
>> // Open a new Session and start transaction.
>> final Session session = sessionFactory.openSession();
>> session.beginTransaction();
>>
>> // Create a library.
>> Library library = LibraryFactory.eINSTANCE.createLibrary();
>> library.setName("My Library");
>> // Make it persistent.
>> session.save(library);
>>
>> // Create a writer...
>> Writer writer = LibraryFactory.eINSTANCE.createWriter();
>> writer.setName("JRR Tolkien");
>>
>> // ...and one of his books.
>> Book book = LibraryFactory.eINSTANCE.createBook();
>> book.setAuthor(writer);
>> book.setPages(305);
>> book.setTitle("The Hobbit");
>> book.setCategory(BookCategory.SCIENCE_FICTION);
>>
>> // Add the Writer and Book to the Library. They are made
>> // persistent automatically because the Library is already
>> // persistent.
>> library.getWriters().add(writer);
>> library.getBooks().add(book);
>>
>> // Commit the changes to the database.
>> session.getTransaction().commit();
>> // Close the session. Not necessary if
>> session.close();
>>
>> ----
>>
>> Results in
>>
>> ---
>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>> Tolkien',NULL,NULL,'Library','1',-2)
>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>> Hobbit',305,'ScienceFiction',1,NULL,NULL,'Library','1',-3)
>> DELETE FROM "writer" WHERE E_ID=1
>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>> Tolkien',1,0,'Library','1',-2)
>> DELETE FROM "book" WHERE E_ID=1
>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>> ---
>>
>> Where as all that was really needed was
>>
>> ---
>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>> Tolkien',1,0,'Library','1',-2)
>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>> ---
>>
>> Is this a Teneo or hibernate issue? Its been a while since I did
>> hibernate but don't remember that?
>>
>>
Re: [Teneo] Insert / Delete instead of Update [message #620295 is a reply to message #129467] Wed, 03 September 2008 14:03 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Andrew,
You can generate a mapping separately (call HbHelper.generateMapping) and store it a
hibernate.hbm.xml file. Then you can tell Teneo to use a mapping file (set the option
USE_MAPPING_FILE to "true"), if your mapping file is not called hibernate.hbm.xml or is not located
in the packages of the model then you can set the mapping file path through the option
MAPPING_FILE_PATH.

The update of the database schema is controlled through hibernate and its option
hibernate.hbm2ddl.auto (see the hibernate manual for more information). So even if Teneo generates a
new mapping, the database schema is only updated if this option is set to create or update. But
having a separate mapping file is always the safest approach.

gr. Martin

Andrew H wrote:
> OK that's far more sensible. I don't believe I set any options other
> than those in the tutorial.
>
> Either way, I'm only evaluating for now and based on what you have shown
> here I am happy with how it was handled, so that's good enough for me
> for now.
>
> BTW I assume there is a way to separate the generate schema steps from
> the running of the application? We would manage the schema evolution
> carefully and not want this to happen when we run the app. Any pointers
> there?
>
> Thanks for your help
>
>
> Martin Taal wrote:
>
>> Hi Andrew,
>> I executed the exact same code as you did and got this result:
>
>> 0 [main] DEBUG org.hibernate.SQL - insert into `library` (e_version,
> `name`) values (?, ?)
>> 3501 [main] DEBUG org.hibernate.SQL - insert into `writer` (e_version,
> `name`, econtainer_class,
>> e_container, e_container_featureid) values (?, ?, ?, ?, ?)
>> 3509 [main] DEBUG org.hibernate.SQL - insert into `book` (e_version,
> `title`, `pages`, `category`,
>> econtainer_class, e_container, e_container_featureid) values (?, ?, ?,
>> ?, ?,
> ?, ?)
>> 3581 [main] DEBUG org.hibernate.SQL - update `writer` set
> `library_writers_e_id`=?,
>> `library_writers_idx`=? where e_id=?
>> 3589 [main] DEBUG org.hibernate.SQL - update `book` set
> `library_books_e_id`=?,
>> `library_books_idx`=? where e_id=?
>> 3590 [main] DEBUG org.hibernate.SQL - update `book` set
> `book_author_e_id`=?, `writer_books_idx`=?
>> where e_id=?
>
>> This set of statements is correct. First create the objects and then
>> update
> their internal relations.
>
>> Maybe you set different options and therefore have a different
>> mapping. Can
> you post the mapping?
>> You can get it from the datastore.getMappingXML().
>
>> Btw, support for Teneo is given on the EMF newsgroup which I cc-ed.
>
>> gr. Martin
>
>> Andrew H wrote:
>>> I'm running the library example and looking in the hypersonic logs
>>> and noticed some odd behaviour.
>>>
>>> It appears that no updates are ever issued but instead rows are
>>> deleted and inserted. Also a lot more SQL is executed than would be
>>> required. Obviously you need to allow for some inefficiencies with a
>>> persistence framework but it seemed excessive to me.
>>>
>>> Running the first section of the example as follows
>>>
>>> ----
>>> // Open a new Session and start transaction.
>>> final Session session = sessionFactory.openSession();
>>> session.beginTransaction();
>>>
>>> // Create a library.
>>> Library library = LibraryFactory.eINSTANCE.createLibrary();
>>> library.setName("My Library");
>>> // Make it persistent.
>>> session.save(library);
>>>
>>> // Create a writer...
>>> Writer writer = LibraryFactory.eINSTANCE.createWriter();
>>> writer.setName("JRR Tolkien");
>>>
>>> // ...and one of his books.
>>> Book book = LibraryFactory.eINSTANCE.createBook();
>>> book.setAuthor(writer);
>>> book.setPages(305);
>>> book.setTitle("The Hobbit");
>>> book.setCategory(BookCategory.SCIENCE_FICTION);
>>>
>>> // Add the Writer and Book to the Library. They are made
>>> // persistent automatically because the Library is already
>>> // persistent.
>>> library.getWriters().add(writer);
>>> library.getBooks().add(book);
>>>
>>> // Commit the changes to the database.
>>> session.getTransaction().commit();
>>> // Close the session. Not necessary if
>>> session.close();
>>>
>>> ----
>>>
>>> Results in
>>>
>>> ---
>>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>> Tolkien',NULL,NULL,'Library','1',-2)
>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>> Hobbit',305,'ScienceFiction',1,NULL,NULL,'Library','1',-3)
>>> DELETE FROM "writer" WHERE E_ID=1
>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>> Tolkien',1,0,'Library','1',-2)
>>> DELETE FROM "book" WHERE E_ID=1
>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>>> ---
>>>
>>> Where as all that was really needed was
>>>
>>> ---
>>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>> Tolkien',1,0,'Library','1',-2)
>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>>> ---
>>>
>>> Is this a Teneo or hibernate issue? Its been a while since I did
>>> hibernate but don't remember that?
>>>
>>>
>
>
>
>


--

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] Insert / Delete instead of Update [message #620299 is a reply to message #129505] Fri, 05 September 2008 07:32 Go to previous message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
Thanks Martin

Martin Taal wrote:

> Hi Andrew,
> You can generate a mapping separately (call HbHelper.generateMapping) and
store it a
> hibernate.hbm.xml file. Then you can tell Teneo to use a mapping file (set
the option
> USE_MAPPING_FILE to "true"), if your mapping file is not called
hibernate.hbm.xml or is not located
> in the packages of the model then you can set the mapping file path through
the option
> MAPPING_FILE_PATH.

> The update of the database schema is controlled through hibernate and its
option
> hibernate.hbm2ddl.auto (see the hibernate manual for more information). So
even if Teneo generates a
> new mapping, the database schema is only updated if this option is set to
create or update. But
> having a separate mapping file is always the safest approach.

> gr. Martin

> Andrew H wrote:
>> OK that's far more sensible. I don't believe I set any options other
>> than those in the tutorial.
>>
>> Either way, I'm only evaluating for now and based on what you have shown
>> here I am happy with how it was handled, so that's good enough for me
>> for now.
>>
>> BTW I assume there is a way to separate the generate schema steps from
>> the running of the application? We would manage the schema evolution
>> carefully and not want this to happen when we run the app. Any pointers
>> there?
>>
>> Thanks for your help
>>
>>
>> Martin Taal wrote:
>>
>>> Hi Andrew,
>>> I executed the exact same code as you did and got this result:
>>
>>> 0 [main] DEBUG org.hibernate.SQL - insert into `library` (e_version,
>> `name`) values (?, ?)
>>> 3501 [main] DEBUG org.hibernate.SQL - insert into `writer` (e_version,
>> `name`, econtainer_class,
>>> e_container, e_container_featureid) values (?, ?, ?, ?, ?)
>>> 3509 [main] DEBUG org.hibernate.SQL - insert into `book` (e_version,
>> `title`, `pages`, `category`,
>>> econtainer_class, e_container, e_container_featureid) values (?, ?, ?,
>>> ?, ?,
>> ?, ?)
>>> 3581 [main] DEBUG org.hibernate.SQL - update `writer` set
>> `library_writers_e_id`=?,
>>> `library_writers_idx`=? where e_id=?
>>> 3589 [main] DEBUG org.hibernate.SQL - update `book` set
>> `library_books_e_id`=?,
>>> `library_books_idx`=? where e_id=?
>>> 3590 [main] DEBUG org.hibernate.SQL - update `book` set
>> `book_author_e_id`=?, `writer_books_idx`=?
>>> where e_id=?
>>
>>> This set of statements is correct. First create the objects and then
>>> update
>> their internal relations.
>>
>>> Maybe you set different options and therefore have a different
>>> mapping. Can
>> you post the mapping?
>>> You can get it from the datastore.getMappingXML().
>>
>>> Btw, support for Teneo is given on the EMF newsgroup which I cc-ed.
>>
>>> gr. Martin
>>
>>> Andrew H wrote:
>>>> I'm running the library example and looking in the hypersonic logs
>>>> and noticed some odd behaviour.
>>>>
>>>> It appears that no updates are ever issued but instead rows are
>>>> deleted and inserted. Also a lot more SQL is executed than would be
>>>> required. Obviously you need to allow for some inefficiencies with a
>>>> persistence framework but it seemed excessive to me.
>>>>
>>>> Running the first section of the example as follows
>>>>
>>>> ----
>>>> // Open a new Session and start transaction.
>>>> final Session session = sessionFactory.openSession();
>>>> session.beginTransaction();
>>>>
>>>> // Create a library.
>>>> Library library = LibraryFactory.eINSTANCE.createLibrary();
>>>> library.setName("My Library");
>>>> // Make it persistent.
>>>> session.save(library);
>>>>
>>>> // Create a writer...
>>>> Writer writer = LibraryFactory.eINSTANCE.createWriter();
>>>> writer.setName("JRR Tolkien");
>>>>
>>>> // ...and one of his books.
>>>> Book book = LibraryFactory.eINSTANCE.createBook();
>>>> book.setAuthor(writer);
>>>> book.setPages(305);
>>>> book.setTitle("The Hobbit");
>>>> book.setCategory(BookCategory.SCIENCE_FICTION);
>>>>
>>>> // Add the Writer and Book to the Library. They are made
>>>> // persistent automatically because the Library is already
>>>> // persistent.
>>>> library.getWriters().add(writer);
>>>> library.getBooks().add(book);
>>>>
>>>> // Commit the changes to the database.
>>>> session.getTransaction().commit();
>>>> // Close the session. Not necessary if
>>>> session.close();
>>>>
>>>> ----
>>>>
>>>> Results in
>>>>
>>>> ---
>>>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>>> Tolkien',NULL,NULL,'Library','1',-2)
>>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>>> Hobbit',305,'ScienceFiction',1,NULL,NULL,'Library','1',-3)
>>>> DELETE FROM "writer" WHERE E_ID=1
>>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>>> Tolkien',1,0,'Library','1',-2)
>>>> DELETE FROM "book" WHERE E_ID=1
>>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>>>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>>>> ---
>>>>
>>>> Where as all that was really needed was
>>>>
>>>> ---
>>>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>>> Tolkien',1,0,'Library','1',-2)
>>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>>>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>>>> ---
>>>>
>>>> Is this a Teneo or hibernate issue? Its been a while since I did
>>>> hibernate but don't remember that?
>>>>
>>>>
>>
>>
>>
>>
Re: [Teneo] Insert / Delete instead of Update [message #620300 is a reply to message #129551] Fri, 05 September 2008 07:50 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
One thing I forgot to mention is that the mapping file probably needs to be explicitly flagged in
the build.properties to be copied to the output directory.

gr. Martin

Andrew H wrote:
> Thanks Martin
>
> Martin Taal wrote:
>
>> Hi Andrew,
>> You can generate a mapping separately (call HbHelper.generateMapping) and
> store it a
>> hibernate.hbm.xml file. Then you can tell Teneo to use a mapping file
>> (set
> the option
>> USE_MAPPING_FILE to "true"), if your mapping file is not called
> hibernate.hbm.xml or is not located
>> in the packages of the model then you can set the mapping file path
>> through
> the option
>> MAPPING_FILE_PATH.
>
>> The update of the database schema is controlled through hibernate and its
> option
>> hibernate.hbm2ddl.auto (see the hibernate manual for more
>> information). So
> even if Teneo generates a
>> new mapping, the database schema is only updated if this option is set to
> create or update. But
>> having a separate mapping file is always the safest approach.
>
>> gr. Martin
>
>> Andrew H wrote:
>>> OK that's far more sensible. I don't believe I set any options other
>>> than those in the tutorial.
>>>
>>> Either way, I'm only evaluating for now and based on what you have
>>> shown here I am happy with how it was handled, so that's good enough
>>> for me for now.
>>>
>>> BTW I assume there is a way to separate the generate schema steps
>>> from the running of the application? We would manage the schema
>>> evolution carefully and not want this to happen when we run the app.
>>> Any pointers there?
>>>
>>> Thanks for your help
>>>
>>>
>>> Martin Taal wrote:
>>>
>>>> Hi Andrew,
>>>> I executed the exact same code as you did and got this result:
>>>
>>>> 0 [main] DEBUG org.hibernate.SQL - insert into `library`
>>>> (e_version,
>>> `name`) values (?, ?)
>>>> 3501 [main] DEBUG org.hibernate.SQL - insert into `writer` (e_version,
>>> `name`, econtainer_class,
>>>> e_container, e_container_featureid) values (?, ?, ?, ?, ?)
>>>> 3509 [main] DEBUG org.hibernate.SQL - insert into `book` (e_version,
>>> `title`, `pages`, `category`,
>>>> econtainer_class, e_container, e_container_featureid) values (?, ?,
>>>> ?, ?, ?,
>>> ?, ?)
>>>> 3581 [main] DEBUG org.hibernate.SQL - update `writer` set
>>> `library_writers_e_id`=?,
>>>> `library_writers_idx`=? where e_id=?
>>>> 3589 [main] DEBUG org.hibernate.SQL - update `book` set
>>> `library_books_e_id`=?,
>>>> `library_books_idx`=? where e_id=?
>>>> 3590 [main] DEBUG org.hibernate.SQL - update `book` set
>>> `book_author_e_id`=?, `writer_books_idx`=?
>>>> where e_id=?
>>>
>>>> This set of statements is correct. First create the objects and then
>>>> update
>>> their internal relations.
>>>
>>>> Maybe you set different options and therefore have a different
>>>> mapping. Can
>>> you post the mapping?
>>>> You can get it from the datastore.getMappingXML().
>>>
>>>> Btw, support for Teneo is given on the EMF newsgroup which I cc-ed.
>>>
>>>> gr. Martin
>>>
>>>> Andrew H wrote:
>>>>> I'm running the library example and looking in the hypersonic logs
>>>>> and noticed some odd behaviour.
>>>>>
>>>>> It appears that no updates are ever issued but instead rows are
>>>>> deleted and inserted. Also a lot more SQL is executed than would be
>>>>> required. Obviously you need to allow for some inefficiencies with
>>>>> a persistence framework but it seemed excessive to me.
>>>>>
>>>>> Running the first section of the example as follows
>>>>>
>>>>> ----
>>>>> // Open a new Session and start transaction.
>>>>> final Session session = sessionFactory.openSession();
>>>>> session.beginTransaction();
>>>>>
>>>>> // Create a library.
>>>>> Library library = LibraryFactory.eINSTANCE.createLibrary();
>>>>> library.setName("My Library");
>>>>> // Make it persistent.
>>>>> session.save(library);
>>>>>
>>>>> // Create a writer...
>>>>> Writer writer = LibraryFactory.eINSTANCE.createWriter();
>>>>> writer.setName("JRR Tolkien");
>>>>>
>>>>> // ...and one of his books.
>>>>> Book book = LibraryFactory.eINSTANCE.createBook();
>>>>> book.setAuthor(writer);
>>>>> book.setPages(305);
>>>>> book.setTitle("The Hobbit");
>>>>> book.setCategory(BookCategory.SCIENCE_FICTION);
>>>>>
>>>>> // Add the Writer and Book to the Library. They are made
>>>>> // persistent automatically because the Library is already
>>>>> // persistent.
>>>>> library.getWriters().add(writer);
>>>>> library.getBooks().add(book);
>>>>>
>>>>> // Commit the changes to the database.
>>>>> session.getTransaction().commit();
>>>>> // Close the session. Not necessary if
>>>>> session.close();
>>>>>
>>>>> ----
>>>>>
>>>>> Results in
>>>>>
>>>>> ---
>>>>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>>>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>>>> Tolkien',NULL,NULL,'Library','1',-2)
>>>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>>>> Hobbit',305,'ScienceFiction',1,NULL,NULL,'Library','1',-3)
>>>>> DELETE FROM "writer" WHERE E_ID=1
>>>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>>>> Tolkien',1,0,'Library','1',-2)
>>>>> DELETE FROM "book" WHERE E_ID=1
>>>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>>>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>>>>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>>>>> ---
>>>>>
>>>>> Where as all that was really needed was
>>>>>
>>>>> ---
>>>>> INSERT IGNORE INTO "library" VALUES(1,'Library',0,'My Library')
>>>>> INSERT IGNORE INTO "writer" VALUES(1,'Writer',0,'JRR
>>>>> Tolkien',1,0,'Library','1',-2)
>>>>> INSERT IGNORE INTO "book" VALUES(1,'Book',0,'The
>>>>> Hobbit',305,'ScienceFiction',1,1,0,'Library','1',-3)
>>>>> INSERT IGNORE INTO "writer_books" VALUES(1,1,0)
>>>>> ---
>>>>>
>>>>> Is this a Teneo or hibernate issue? Its been a while since I did
>>>>> hibernate but don't remember that?
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>
>
>
>


--

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
Previous Topic:[Emfatic] Detail-less annotations
Next Topic:[EMF Compare] Infos about the planned "patch/changeset model" feature?
Goto Forum:
  


Current Time: Wed Jul 08 09:01:31 GMT 2020

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

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

Back to the top