-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Seltsames Verhalten bei selbst erzeugter ID
PostPosted: Mon Mar 20, 2006 10:46 am 
Newbie

Joined: Mon Mar 20, 2006 10:31 am
Posts: 5
Hallo!

Ich habe hier gerade ein setsames Problem: Wenn ich folgendes xml zum Erzeugen eine hibernate-objektes (und der DB und der files....) verwende, so klappt das wunderbar, und wenn ich auf einem derart erzeugten objekt session.save(obj) aufrufe, so wandert das Objekt mit der gesammten Substruktur brav in die DB.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="false" default-cascade="all-delete-orphan" default-lazy="false">
<class name="de.my.Product" table="Product">
<id name="Hjid" type="org.hibernate.type.LongType">
<generator class="native"/>
</id>
<discriminator type="org.hibernate.type.StringType">
<column name="Hjtype"/>
</discriminator>
....

Verwende ich hingegen einen von mir selbst erzeugten Primärschlüssel, so klappt das auch erst mal ganz prima, und ich kann das objekt auch speichern, allerdings wird nur die Substruktur gespeichert, der Eintrag für das Produkt selber fehlt in der DB, will sagen keine Zeile in der Product Tabelle:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="false" default-cascade="all-delete-orphan" default-lazy="false">
<class name="de.my.Product" table="Product">
<id name="DigitalIcpn" type="org.hibernate.type.StringType">
<generator class="assigned"/>
</id>
<discriminator type="org.hibernate.type.StringType">
<column name="Hjtype"/>
</discriminator>
....

Hat hier irgendwer eine Idee, was ich übersehe? Ich studier schon eine Zeit lang die Doku, habe aber noch nichts wirklich brauchbares dazu gefunden.

Auch Hinweise was man mal probieren könnte sind herzlich willkommen.

Grüßle und danke schon mal im Voraus


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 12:36 pm 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Kannst du mal den code posten, der fehlschlägt?

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 12:47 pm 
Newbie

Joined: Mon Mar 20, 2006 10:31 am
Posts: 5
Ok, der ist wirklich ehr übersichtlich:

Ich pumpe das Produkt aus einem xml file hoch in den Speicher, und save es:

private void handleProduct(File xml){
ProductData data = (ProductData) unmarshaller.unmarshal(getSource(xml));
Product xmlProduct = (Product)data.getProduct().iterator().next();
Session session = hibernateTemplate.getSessionFactory().openSession();
session.save(xmlProduct);
result.addInfoMessage("Imported: "+xmlProduct.getDigitalIcpn());
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 5:26 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Und Du bist wirklich sicher, dass im XML ne id steht? Ich glaub da brauch ich ein debug log um da was sagen zu können ;-)

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 8:32 am 
Newbie

Joined: Mon Mar 20, 2006 10:31 am
Posts: 5
Leider bin ich mir da sicher, denn wenn ich hibernate die ID generiren lasse, ist das feld, welches ich gerne als ID hätte, nachher gefüllt.
Hier ist mal, was ich im Log finde, wenn ich hibernate seine ID verwenden lasse (er kommt da gerade vom verewigen der substruktur wieder, wenn du davor noch was brauchst, einfach melden):

Code:
...
DEBUG QueueWorker org.hibernate.event.def.DefaultSaveOrUpdateEventListener - saving transient instance
DEBUG QueueWorker org.hibernate.event.def.AbstractSaveEventListener - saving [de.arvato.repository.emi.impl.ProductImpl#<null>]
DEBUG QueueWorker org.hibernate.event.def.AbstractSaveEventListener - executing insertions
DEBUG Finalizer org.hibernate.jdbc.ConnectionManager - running Session.finalize()
DEBUG Finalizer org.hibernate.jdbc.ConnectionManager - running Session.finalize()
DEBUG Finalizer org.hibernate.jdbc.ConnectionManager - running Session.finalize()
DEBUG QueueWorker org.hibernate.engine.Cascades - processing cascade ACTION_SAVE_UPDATE for: de.arvato.repository.emi.impl.ProductImpl
DEBUG QueueWorker org.hibernate.engine.Cascades - cascading to saveOrUpdate: de.arvato.repository.emi.ProdRegional
...
DEBUG QueueWorker org.hibernate.engine.Cascades - done processing cascade ACTION_SAVE_UPDATE for: de.arvato.repository.emi.impl.ProductImpl
DEBUG QueueWorker org.hibernate.engine.Versioning - Seeding: 0
DEBUG QueueWorker org.hibernate.persister.entity.BasicEntityPersister - Inserting entity: de.arvato.repository.emi.impl.ProductImpl (native id)
DEBUG QueueWorker org.hibernate.persister.entity.BasicEntityPersister - Version: 0
DEBUG QueueWorker org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG QueueWorker org.hibernate.SQL - insert into Product (Hjversion, Regional, DisplayArtist, PNoticeNationality, Grid, PNotice, Label, RepertoireOwner, AvailableTerritories, Contributors, Components, TotalComponents, LabelGroup, ParentalAdvisory, LocalTitle, DigitalOnly, Genre, Bundled, LocalArtist, DigitalIcpn, CNotice, TotalTracks, ProductType, Title, TotalDuration, DigitalUpc, Hjtype) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'de.arvato.repository.emi.Product')
DEBUG QueueWorker org.hibernate.jdbc.AbstractBatcher - preparing statement
DEBUG QueueWorker org.hibernate.persister.entity.BasicEntityPersister - Dehydrating entity: [de.arvato.repository.emi.impl.ProductImpl#<null>]
DEBUG QueueWorker org.hibernate.type.LongType - binding '0' to parameter: 1
DEBUG QueueWorker org.hibernate.type.LongType - binding '1' to parameter: 2
DEBUG QueueWorker org.hibernate.type.StringType - binding 'Starsailor' to parameter: 3
DEBUG QueueWorker org.hibernate.type.StringType - binding '' to parameter: 4
DEBUG QueueWorker org.hibernate.type.StringType - binding '' to parameter: 5
DEBUG QueueWorker org.hibernate.type.StringType - binding '(P) 2005 The copyright in this sound recording is owned by EMI Records Ltd' to parameter: 6
DEBUG QueueWorker org.hibernate.type.StringType - binding 'EMI UK' to parameter: 7
DEBUG QueueWorker org.hibernate.type.StringType - binding 'EMI UK' to parameter: 8
DEBUG QueueWorker org.hibernate.type.LongType - binding '1' to parameter: 9
DEBUG QueueWorker org.hibernate.type.LongType - binding '1' to parameter: 10
DEBUG QueueWorker org.hibernate.type.LongType - binding '1' to parameter: 11
DEBUG QueueWorker org.hibernate.type.BigIntegerType - binding '1' to parameter: 12
DEBUG QueueWorker org.hibernate.type.StringType - binding 'EMI UK' to parameter: 13
DEBUG QueueWorker org.hibernate.type.StringType - binding 'No' to parameter: 14
DEBUG QueueWorker org.hibernate.type.StringType - binding '' to parameter: 15
DEBUG QueueWorker org.hibernate.type.StringType - binding 'No' to parameter: 16
DEBUG QueueWorker org.hibernate.type.StringType - binding 'Pop' to parameter: 17
DEBUG QueueWorker org.hibernate.type.StringType - binding 'No' to parameter: 18
DEBUG QueueWorker org.hibernate.type.StringType - binding '' to parameter: 19
DEBUG QueueWorker org.hibernate.type.StringType - binding '0094634227452' to parameter: 20
DEBUG QueueWorker org.hibernate.type.StringType - binding '(C) 2005 EMI Records Ltd This label copy information is the subject of copyright protection. All rights reserved. (C) 2005 EMI Records Ltd' to parameter: 21
DEBUG QueueWorker org.hibernate.type.BigIntegerType - binding '11' to parameter: 22
DEBUG QueueWorker org.hibernate.type.StringType - binding 'Album' to parameter: 23
DEBUG QueueWorker org.hibernate.type.StringType - binding 'On The Outside' to parameter: 24
DEBUG QueueWorker org.hibernate.type.StringType - binding '00:38:35' to parameter: 25
DEBUG QueueWorker org.hibernate.type.StringType - binding '094634227452' to parameter: 26
DEBUG QueueWorker org.hibernate.id.IdentifierGeneratorFactory - Natively generated identity: 1
DEBUG QueueWorker org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG QueueWorker org.hibernate.jdbc.AbstractBatcher - closing statement
DEBUG QueueWorker org.hibernate.engine.Cascades - processing cascade ACTION_SAVE_UPDATE for: de.arvato.repository.emi.impl.ProductImpl
DEBUG QueueWorker org.hibernate.engine.Cascades - done processing cascade ACTION_SAVE_UPDATE for: de.arvato.repository.emi.impl.ProductImpl


Und so sieht es aus, wenn ich die DigitalIcpn als id verwenden möchte (die ist gefüllt, siehe parameter 20 oben)

Code:
...
DEBUG QueueWorker org.hibernate.event.def.DefaultSaveOrUpdateEventListener - saving transient instance
DEBUG QueueWorker org.hibernate.event.def.AbstractSaveEventListener - generated identifier: 0094634227452, using strategy: org.hibernate.id.Assigned
DEBUG QueueWorker org.hibernate.event.def.AbstractSaveEventListener - saving [de.arvato.repository.emi.impl.ProductImpl#0094634227452]
DEBUG QueueWorker org.hibernate.engine.Cascades - processing cascade ACTION_SAVE_UPDATE for: de.arvato.repository.emi.impl.ProductImpl
DEBUG QueueWorker org.hibernate.engine.Cascades - cascading to saveOrUpdate: de.arvato.repository.emi.ProdRegional
...
DEBUG QueueWorker org.hibernate.engine.Cascades - done processing cascade ACTION_SAVE_UPDATE for: de.arvato.repository.emi.impl.ProductImpl
DEBUG QueueWorker org.hibernate.engine.Versioning - Seeding: 0
DEBUG QueueWorker org.hibernate.engine.Cascades - processing cascade ACTION_SAVE_UPDATE for: de.arvato.repository.emi.impl.ProductImpl
DEBUG QueueWorker org.hibernate.engine.Cascades - done processing cascade ACTION_SAVE_UPDATE for: de.arvato.repository.emi.impl.ProductImpl
DEBUG QueueWorker de.arvato.repository.emi.EmiProductDataHandler - Imported product 0094634227452


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 5:22 am 
Newbie

Joined: Mon Mar 20, 2006 10:31 am
Posts: 5
Hallo und danke für die Unterstützung. Das Problem lag an einer völlig anderen Stelle. Höm ich blamier mich hier glaub ich gerade... Alter code der noch im Classpath herumliegt fürht manchmal zu seltsamten Verhalten


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 11:24 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
*lach* tja sowas soll vorkommen ;-)

_________________
Please don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.