Results 1 to 6 of 6

Thread: Question to Hibernate in Java Development

  1. #1
    Join Date
    Apr 2010
    Posts
    59

    Question to Hibernate in Java Development

    I have called an inheritance hierarchy in Hibernate, the objects we AbstractBase times and Sub1, Sub2. The Strategy is TABLE_PER_CLASS with unions (Business-default, the DB is already there). A class is now assigned to some of the objects of this hierarchy, and it Sub1 and / or Sub2 may be displayed:
    Code:
    public List <AbstractBase> GetSubObjects () // Fetch Mode: Lazy
    Will I get all sub-objects. But I can not check with instanceof, whether it is in each case to Sub1 or Sub2 (because the returned object is a proxy of AbstractBase). After I had the annotation = @ Proxy (lazy false) set for the AbstractBase class, but it works also without problems. Now to my question: I have seen that by this annotation is always a separate query is issued.
    SQL: FROM LEFT JOIN FETCH xy.subObjects xy "---> Sets from N + 1 queries.
    Actually JONI FETCH should already get all the data in the first query, but apparently is still working with Proxis internally somewhere, and the lazy = false annotation then provides for loading the data. Does anyone have an idea?

  2. #2
    Join Date
    Mar 2008
    Posts
    232

    Re: Question to Hibernate in Java Development

    You are you really sure that you want to give up lazy-loading, simply because instance of does not work for proxies? The standard in the use of proxies is to dispense with instance of in the implementation of equals () on Hibernate. Also, I would not want to miss LazyLoading. As far as I know, there is always two Hibernate sell Selects, as a Union are not even really make sense, but rather would be less performance (they are identical so no data is available, and a union would lead to large Result, in which ever half of the columns empty).

  3. #3
    Join Date
    Mar 2008
    Posts
    258

    Re: Question to Hibernate in Java Development

    The instance of problem I usually solve the fact that I define a method in the parent, which specifies the type. This is then implemented by sub1/sub2. The following is an example :
    Code:
    public enum (SubType 
    SUB1, 
    SUB2 
    ) 
    
    public abstract class Parent ( 
    public abstract SubType getType (); 
    ) 
    
    public class Sub1 extends Parent ( 
    SubType public getType () ( 
    return SubType.SUB1 
    )

  4. #4
    Join Date
    Mar 2008
    Posts
    258

    Re: Question to Hibernate in Java Development

    The instance of problem I usually solve the fact that I define a method in the parent, which specifies the type. This is then implemented by sub1/sub2. The following is an example :
    Code:
    public enum (SubType 
    SUB1, 
    SUB2 
    ) 
    
    public abstract class Parent ( 
    public abstract SubType getType (); 
    ) 
    
    public class Sub1 extends Parent ( 
    SubType public getType () ( 
    return SubType.SUB1 
    )

  5. #5
    Join Date
    Apr 2010
    Posts
    59

    Re: Question to Hibernate in Java Development

    Thank you for the very interesting answers. I am aware that I can instead of instanceof example Session.getEntityName (object) use, or better yet HibernateProxyHelper.getClassWithoutInitializingProxy (object). However, I would like to recognize not only to what each subclass returns me Hibernate, but also read the specific data of this sub can. In other words,
    if (object instanceof Sub1) (/ / Or whatever else query
    Sub1 sub1 = (SUB1) object;
    sub1.getSpecialSub1Data ();
    )
    Of course I can an object, which is a proxy for the parent class, not cast in Sub1, and that is my problem. So I did without lazy loading, which works so well, but I wonder about the additional query ...

  6. #6
    Join Date
    Oct 2008
    Posts
    167

    Re: Question to Hibernate in Java Development

    You pack why not simply an interface on your domain object - you can then cast to the problem. This also has the advantage that you're somewhat detached from Hibernate and also any necessary technical methods do not provide global. You have two completely separate tables, which are simply packed java-sided in an inheritance hierarchy. In a Union should also two internal DB queries will be fired, then the results are mixed in a result set (in which case most of the columns were both empty) and the whole mess would have to be transferred. Usually it is faster two separate queries to the DB to send, so that Hibernate does. To what extent this can be disabled for a particular case, I do not know - I would tuck here and only then bother, when there really is a problem.

Similar Threads

  1. How to choose right development module for Java programming
    By Karumbu in forum Software Development
    Replies: 10
    Last Post: 22-10-2012, 01:09 PM
  2. Hibernate with Java Persistence API
    By Valliy in forum Software Development
    Replies: 5
    Last Post: 18-09-2010, 10:06 PM
  3. Don't about Hibernate Framework of java
    By ScarFace 01 in forum Software Development
    Replies: 5
    Last Post: 23-01-2010, 09:02 AM
  4. DirectSound application development question.
    By sunwins in forum Windows Software
    Replies: 5
    Last Post: 16-09-2009, 03:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,486,957.60127 seconds with 17 queries