-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem: One-To-One abhängige Objekte werden nicht geladen
PostPosted: Mon Oct 06, 2008 7:03 am 
Newbie

Joined: Fri Jul 25, 2008 4:03 am
Posts: 7
Hallo,

ich habe eine Problem mit einer One-To-One Beziehung, die nicht geladen wird, obwohl ich FetchMode.JOIN angegeben habe:

Code:
@Entity
@Table(name="DATA")
public class Data implements java.io.Serializable {

   @Id     
   @GeneratedValue(strategy = GenerationType.AUTO)
   private long id;

       ......   

   @OneToOne (cascade = CascadeType.ALL, fetch = FetchType.LAZY)
   @PrimaryKeyJoinColumn (name = "data_id")
        private Score score = null;

   @OneToMany (targetEntity = TextData.class, mappedBy = "Data", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
   private Set<TextData> schufaTextData = new HashSet<TextData>(0);
   
.....



Code:
@Entity
@Table(name="SCORE")
public class Score  implements java.io.Serializable {

    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
   @Column(name="attribute_code")
    private String attributeCode;
   @Column(name="description")
    private String description;
   @Column(name="score_value")
    private int scoreValue;
   @Column(name="risk_rate")
    private float riskRate;
   @Column(name="score_range")
    private String scoreRange;
   @Column(name="text")
    private String text;
   @OneToOne (targetEntity = SchufaData.class)
    @JoinColumn (name = "data_id")
    private Data data;

....


Ich lade die Sachen mit Spring und Hibernate:

Code:
   @SuppressWarnings("unchecked")
   public List<Data> findDataByIpNbrLess24h(String ipNbr) {
      final String finalIpNbr = ipNbr;
      return (List<Data>)getHibernateTemplate().execute(new HibernateCallback() {
         public Object doInHibernate(Session session) {
            Calendar critDateTime = Calendar.getInstance();
            critDateTime.set(Calendar.DATE, critDateTime.get(Calendar.DATE)-1);

            Criteria criteria = session.createCriteria(Data.class);
            criteria.add(Restrictions.and(Restrictions.eq("ipNbr", finalIpNbr),
                      Restrictions.gt("insertDate", critDateTime.getTime())));
            criteria.setFetchMode("score", FetchMode.JOIN);
            criteria.setFetchMode("textData", FetchMode.JOIN);
            return criteria.list();
         }
         });
   }


Die TextData Liste wird einwandfrei geladen, die One-To-One Beziehung nicht. Hat jemand eine Idee was ich falsch mache?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2008 6:20 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
2 Dinge fallen mir auf:

- beim Mapping der bidirektionalen Beziehung Score/Data muss eine Seite angeben: "mappedBy"

- du hast die Strategie LAZY-Loading eingeschaltet - weshalb wunderst du dich dann, dass etwas nicht geladen wird? Du willst doch EAGER-Loading, oder nicht?

_________________
Carlo
-----------------------------------------------------------
please don't forget to rate if this post helped you


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