-->
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.  [ 3 posts ] 
Author Message
 Post subject: Exception bei 1:0..1 Beziehung
PostPosted: Mon Apr 14, 2008 5:17 am 
Newbie

Joined: Sat Feb 09, 2008 3:43 am
Posts: 3
Hi!

Wenn ich Angebote mit Eintrag in Musterangebote aufrufe ist alles okay. So ziemlich.
Wenn ich Angebot ohne einen Eintrag in Musterangebote aufrufe, tritt die Exception auf.
Dabei ist der logging level auf warn in den log4j properties. Setze ich diesen nun auf debug dann werden alle Angebote angezeigt. Hatte zwischenzeiitlich auch einen Verweis von Musterangebote auf Angebot. Dann tritt noch einmal eine andere Exception auf.

Also in der DB haben von 12000 Angeboten ein paar Hundert einen Musternamen. Daher die extra Tabelle. Historisch bedingt muss ich die übernehmen und habe daher eine 1:0..1 Beziehung.

Was ist da los? Welchen Wald sehe ich gerade nicht? Irgendeine Idee?

Hibernate version:
3.2.6

Mapping documents:
@Entity
@Table(name = "angebot")
@NamedQueries(...)
public class Angebot implements Serializable {
@Transient
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ID", nullable = false)
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
@Column(name = "AgNr", nullable = false)
private int agNr;
...
@OneToMany(cascade=CascadeType.ALL,mappedBy="angebot")
@JoinColumn(name="agNr",referencedColumnName="agNr",insertable=false)
private List<Angebotsdaten> angebotsdaten=new ArrayList<Angebotsdaten>();
@ManyToOne
@JoinColumn(name="kdNr",referencedColumnName="lfdNr",insertable=false,updatable=false)
private Kunden kunden;
@OneToOne(optional=true)
@JoinColumn(name="agNr",referencedColumnName="agNr",insertable=false,updatable=false,nullable=true)
private Musterangebote musterangebot;

@Entity
@Table(name = "musterangebote")
@NamedQueries(...)
public class Musterangebote implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ID", nullable = false)
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
@Column(name = "Name")
private String name;
@Column(name = "AgNr",nullable=false)
private int agNr;
@Column(name = "RecordLock")
private Integer recordLock;

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
Exception in thread "AWT-EventQueue-0" org.hibernate.PropertyAccessException: could not get a field value by reflection getter of allrmaster.db.Musterangebote.id
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:35)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:183)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3596)
at org.hibernate.type.EntityType.isEqual(EntityType.java:297)
at org.hibernate.type.ComponentType.isEqual(ComponentType.java:143)
at org.hibernate.engine.CollectionKey.equals(CollectionKey.java:50)
at java.util.HashMap.get(HashMap.java:305)
at org.hibernate.engine.loading.LoadContexts.locateLoadingCollectionEntry(LoadContexts.java:271)
at org.hibernate.engine.loading.CollectionLoadContext.getLoadingCollection(CollectionLoadContext.java:92)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1003)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:646)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:591)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:811)
at allrmaster.dao.AngebotDaoImpl.last(AngebotDaoImpl.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy22.last(Unknown Source)
at allrmaster.gui.AngebotView$8.actionPerformed(AngebotView.java:161)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6041)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5806)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4413)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2440)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Caused by: java.lang.NullPointerException
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:36)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:18)
at java.lang.reflect.Field.get(Field.java:358)
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:32)
... 60 more
Name and version of the database you are using:
MySQL 5.0.51a-3ubuntu5
The generated SQL (show_sql=true):
Hibernate: select angebot0_.ID as ID4_0_, angebotsda1_.ID as ID5_1_, angebot0_.Abholer as Abholer4_0_, angebot0_.Abrufnummer as Abrufnum3_4_0_, angebot0_.AgDat as AgDat4_0_, angebot0_.AgNr as AgNr4_0_, angebot0_.Ansprechpartner as Ansprech6_4_0_, angebot0_.Arbeitsbeginn as Arbeitsb7_4_0_, angebot0_.Frankatur as Frankatur4_0_, angebot0_.GesamtDM as GesamtDM4_0_, angebot0_.GesamtDMMwSt as GesamtD10_4_0_, angebot0_.GesamtEuro as GesamtEuro4_0_, angebot0_.GesamtEuroMwSt as GesamtE12_4_0_, angebot0_.GesamtSkonto as GesamtS13_4_0_, angebot0_.GueltigBis as GueltigBis4_0_, angebot0_.KautionBetrag as Kaution15_4_0_, angebot0_.KautionZahlweise as Kaution16_4_0_, angebot0_.KdNr as KdNr4_0_, angebot0_.Kommentar as Kommentar4_0_, angebot0_.Kostenstelle as Kostens19_4_0_, angebot0_.kdNr as kdNr4_0_, angebot0_.Lieferanschrift as Liefera20_4_0_, angebot0_.Lieferart as Lieferart4_0_, angebot0_.agNr as agNr4_0_, angebot0_.Rechnungsanschrift as Rechnun22_4_0_, angebot0_.RecordLock as RecordLock4_0_, angebot0_.Skonto as Skonto4_0_, angebot0_.Uebergabedatum as Ueberga25_4_0_, angebot0_.Uebergabeort as Ueberga26_4_0_, angebotsda1_.AgNr as AgNr5_1_, angebotsda1_.agNr as agNr5_1_, angebotsda1_.Anzahl as Anzahl5_1_, angebotsda1_.ArtNr as ArtNr5_1_, angebotsda1_.artNr as artNr5_1_, angebotsda1_.Frachtkosten as Frachtko5_5_1_, angebotsda1_.Kommentar as Kommentar5_1_, angebotsda1_.Lager as Lager5_1_, angebotsda1_.Lagerplatz as Lagerplatz5_1_, angebotsda1_.MieteBis as MieteBis5_1_, angebotsda1_.MieteTage as MieteTage5_1_, angebotsda1_.MieteVon as MieteVon5_1_, angebotsda1_.MieteZeit as MieteZeit5_1_, angebotsda1_.Preis as Preis5_1_, angebotsda1_.PreisEuro as PreisEuro5_1_, angebotsda1_.Rabatt as Rabatt5_1_, angebotsda1_.RecordLock as RecordLock5_1_, angebotsda1_.Seriennummer as Serienn17_5_1_, angebotsda1_.Service as Service5_1_, angebotsda1_.Sonderpreis as Sonderp19_5_1_, angebotsda1_.SonderpreisEuro as Sonderp20_5_1_, angebotsda1_.Summe as Summe5_1_, angebotsda1_.SummeEuro as SummeEuro5_1_, angebotsda1_.UhrzeitBis as UhrzeitBis5_1_, angebotsda1_.UhrzeitVon as UhrzeitVon5_1_, angebotsda1_.VersPreis as VersPreis5_1_, angebotsda1_.VersPreisEuro as VersPre26_5_1_, angebotsda1_.VersSumme as VersSumme5_1_, angebotsda1_.Versicherung as Versich28_5_1_, angebotsda1_.agNr as agNr0__, angebotsda1_.ID as ID0__ from angebot angebot0_ left outer join angebotsdaten angebotsda1_ on angebot0_.agNr=angebotsda1_.agNr where angebot0_.AgNr=(select max(angebot2_.AgNr) from angebot angebot2_)
Hibernate: select musterange0_.ID as ID49_0_, musterange0_.AgNr as AgNr49_0_, musterange0_.Name as Name49_0_, musterange0_.RecordLock as RecordLock49_0_ from musterangebote musterange0_ where musterange0_.AgNr=?
Hibernate: select musterange0_.ID as ID49_0_, musterange0_.AgNr as AgNr49_0_, musterange0_.Name as Name49_0_, musterange0_.RecordLock as RecordLock49_0_ from musterangebote musterange0_ where musterange0_.AgNr=?
Hibernate: select musterange0_.ID as ID49_0_, musterange0_.AgNr as AgNr49_0_, musterange0_.Name as Name49_0_, musterange0_.RecordLock as RecordLock49_0_ from musterangebote musterange0_ where musterange0_.AgNr=?
Hibernate: select musterange0_.ID as ID49_0_, musterange0_.AgNr as AgNr49_0_, musterange0_.Name as Name49_0_, musterange0_.RecordLock as RecordLock49_0_ from musterangebote musterange0_ where musterange0_.AgNr=?
Hibernate: select musterange0_.ID as ID49_0_, musterange0_.AgNr as AgNr49_0_, musterange0_.Name as Name49_0_, musterange0_.RecordLock as RecordLock49_0_ from musterangebote musterange0_ where musterange0_.AgNr=?
Hibernate: select musterange0_.ID as ID49_0_, musterange0_.AgNr as AgNr49_0_, musterange0_.Name as Name49_0_, musterange0_.RecordLock as RecordLock49_0_ from musterangebote musterange0_ where musterange0_.AgNr=?
Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 9:36 am 
Newbie

Joined: Sat Feb 09, 2008 3:43 am
Posts: 3
Okay wenn ich statt OneToOne OneToMany verwende dann funktioniert es. Mit entsprechenden Methoden wrappe ich mir das dann so, dass ich dann letztendlich nur auf einen String zugreife und nicht mehr auf eine Liste.
Schöner wäre es natürlich, wenn ich es mit OneToOne hin bekommen hätte.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 21, 2008 4:45 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
agnr ist einmal nullable und einmal nicht

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.