Toplink vs. hibernate getReference implementation

Hello,
hibernate implement EntityManager getReference() to save you a database roundtrip if you do nothing but create an association, with the proxied instance in managed state.
How toplink implement EntityManager getReference() ?
Regards

Note that the only time that returning a "hollow" entity from getReference() will even make any difference is when all three of the following are true:
a) you are setting a unidirectional 1-1 or m-1
b) you already know a priori the identifier of the target entity
c) you have not loaded it recently or plan on loading it any time soon

Similar Messages

  • Can I implement the ORM task without TopLink and Hibernate?

    Can I implement the ORM (Objest/Relational Mapping) task without TopLink and Hibernate tools?

    Any opinions are welcome.

  • Toplink vs hibernate

    hi
    who can i determine which technology is better to use with oracle. Toplink or hybernate
    mostly we use hybernate but I want to know why toplink is better than hybernate
    thanks
    Message was edited by:
    Doug Clarke

    One of the key differences between TopLink and Hibernate is the caching implementation. TopLink provides an object cache where instances can be shared across the application, client, or transaction controlled by mapping metadata and application usage. The benefits of the shared cache are clear where read-only and read-mostly objects can be shared to avoid creating many copies of the objects unnecessarily (performance costs and extra garbage creation).
    If you have more volatile or data types that are not shared you can configure TopLink's caching to be isolated and therefore only cache the objects per client or transaction.
    If you have use cases where you need to ensure you get a transactionally isolated instance of an object you have configured to be held in the shared cache you can access the object within a UnitOfWork. This will make a read-repeatable copy of the object within the 'transaction' that will not be changed by concurrent writes from other committing UnitOfWork.
    Ultimately we work hard to offer TopLink/EclipseLink developers a solution with configurable and flexible options to address a wide variety of requirements. Understanding and leveraging our cache is a key success factor in any application development with TopLink.
    As far as the duplicate SQL comment goes I have reviewed the support request we recently received on this and the issue appears to be that if you change the existence-checking from its default of check-cache to check-database we have a bug where we incorrectly check the database for each registered new instance with a zero PK value. When we see an object with a zero primary key and sequencing configured it should be assumed to be new without requiring the select. We are working with support to get this issue addressed.
    Doug

  • Demo Application to Compare Toplink, JDBC, Hibernate

    Hi
    I Need a Demo Application which is implemented Using Toplink, JDBC, Hibernate to compare the overhead of using Toplink, Hibernate to Using JDBC.
    I got a link to Spring PetClinic Demo which is Implemented using Toplink, JDBC, Hibernate from Google but the spring site has removed this application.
    Please help to get this application or some other demo Application which can be used
    Excuse me for my bad english
    Thanks,
    Raghavendra

    PeClinic Demo Application is included in the Spring Frame work Dowload

  • TopLink vs Hibernate... revisited... again :)

    Would it be possible to get a Toplink versus Hibernate (or other ORM frameworks) going here?
    It seems like the explosive adoption of Hibernate and the associated popularity contest in the industry has put some of us in a position where we're constantly trying to sell the-right-tool-for-the-right-job which, at least for me, seems to disqualify hibernate a lot of times, esp when scalable persistence is a requirement. It seems to be really difficult to convince folks that the popularity of hibernate doesnt mean it's by default the right option.
    I've seen at least two threads on theserverside.com about hibernate versus cayenne, and despite the amount of noise in the threads, there were a few folks making some decent points. The TopLink folks were very quiet on the threads, but I know they were reading :)
    So, anyone out there have any experience comparing TopLink and Hibernate? What do you all see as the shortcomings of each, esp from a technical architecture standpoint? Are GUI tools as overrated as Gavin claims? Where's annotation support for TopLink? Is TopLink overpriced? Is Hibernate's multi-tier non-integrated caching biting anyone on big projects where persistence needs to scale, or is integrated caching overrated? Is Hibernate3 really going to fix shortcomings that TopLink already addresses in current releases? What do you all think the Hibernate crew is doing right that the TopLink crew is doing wrong and vice versa? I'm not assuming any of these questions even merit answer but just interested in some objective discussion in a forum where TopLink guys might have a stronger voice.
    Take care!

    Well, I've only got a few minutes, but I could go on for hours.
    I'll start by saying that I've been doing ORM for longer than many people knew that you could. I had been a previous TOPLink user but went for about two years without having to do any ORM.
    Then, last year I started a new project for a client who insisted we use SqlServer and was hesitant to pay for any software unless it was absolutely necessary. (This is common these days, as the fact that there is so much free software out there encourages folks to try out the free stuff before paying for something that may or may not be better). Comparing the feature list of Hibernate to TOPLink and doing a little checking seemed to indicate that going with Hibernate would be a perfectly reasonable thing to do.
    I will state, uncategorically, that this was the worst technical decision I have ever made in my life... twenty-plus years of Software Application Developing, most of it with object-oriented languages (Smalltalk and Java).
    NOTE: I must couch that statement with the caveat that part of this was due to my naivete about the architectural assumptions I made about Hibernate before including it in my application. If I would have merely learned about Hibernate's architectural assumptions (though this was not easy due to their poor documentation) and allowed these assumptions to drive my development, it would not have been nearly as painful, just yucky. Also, if my objects were much simpler/flatter and I didn't need caching to speed things up, Hibernate could have worked just fine out of the box. Problem is, I had a complex system, needed caching, and Hibernate gave me nightmares as I tried to navigate through it.
    As a test-first developer, I don't care about the GUI tools, as I'm happy to write tests to verify I can store and retrieve objects, then write the mappings and find out if it passes. What I would like is the ability to allow two threads to read the same object and not have to bring two copies of the object into memory or read the database twice. Call me crazy, but it just seems like object identity is a useful thing... perhaps my twenty years of developing object-oriented software has skewed my reasoning and I need to think like folks who haven't been programming as long.
    Hibernate's poor documentation did make it clear that it did not want me to think this way, but it also suggested that, if I wanted to think this way, it could cache objects for me so it wouldn't hit the database twice. And, I'm sure it could have cached objects in some form, but not the form I wanted. Though I thought I followed the instructions on how to set up my cache, I found that reading the same object twice didn't always get the same (as in "==") object back.
    To try to figure out why not (or why other things that an experienced object-oriented software developer couldn't figure out by reading the documentation), I had to dive into the code. This felt like diving into a water source in hopes of finding some gems, but discovering that I was swimming in a sewer full of, well, stuff that you'd find in a sewer.
    Although Hibernate advertises itself as a framework, it is much more of a blackbox framework than a whitebox. Most of the methods and many of the classes are private or protected final. There are very few places to extend what's there. And there are virtually none that allow you to override their architectural assumptions.
    The biggest architectural assumption I found to be problematic was that application developers can't be trusted to know which objects they intended to read and which they intended to write. Therefore, Hibernate "protects" you from having two sessions refer to (that's right, refer to, not modify) a collection of objects.
    In the end, we ended up having to open up the source code and make some modifications in order to make our application run with reasonable performance. We had a lot of fairly deep objects (objects that contained objects that contained objects...) and the idea of not caching the ones that were not being modified across sessions just didn't cut it for us.
    Additionally, we've spent the last few months supporting the app that we finally got into production, and greater than 75% of our bug fixing time has been due to the fact that Hibernate actually reads in objects from several places and it is difficult to tap into THE place an object is read in... because there isn't one. It goes through all sorts of intermediate states and we found out that having one process that is reading objects while another is trying to write the same object can cause some unfortunate side effects, even if you put synchronization locks in the obvious places.
    We ended up with many person months of effort and a lot of special classes getting Hibernate to do what we wanted it to do, and had to open the source code (which will make it hard to ever upgrade to the next version).
    Just recently we started a new project (where Oracle was the corporate standard DB) and decided we'd try to use TOPLink. Having not used it for several years, I had hoped it was going to be much cleaner than Hibernate to hook into our persistence layer. It was a piece of cake. In a few days we were doing what took us months to do with Hibernate, and we didn't have to perform any unnatural acts to get there.
    I would recommend Hibernate to anyone who didn't know how to build a reasonably factored object-oriented system and didn't mind forcing their system architecture to fit Hibernate's architectural assumptions. But, if you think you might have reason to define your own architecture or modify Hibernate's default behavior, TOPLink is well worth the licensing fees. Not to mention the cost of your sanity.
    Is Hibernate really free? Only if you don't value your time. I also found that you can buy outrageously priced support from JBoss to make up for their poor documentation on their poorly architected ORM blackbox framework. The documentation for TOPLink is far superior, and the simplicity of doing simple customizations and tweaks is like night and day.

  • JPA: Toplink vs Hibernate

    I am using netbeans 5.5 and I want to use JPA. I am in favor of hibernate, but why does the netbeans has toplink being the default persistence library of JPA? What are the difference between toplink and hibernate if I'll be using JPA?
    By the way, I've seen an article "Using JPA in tomcat" and I would really like to use JPA in tomcat as I think it is much faster and lighter than Glassfish. But the article also uses toplink as the persistence library? Could someone guide me in using hibernate?

    This is an video from NetBeans site. Take a look.
    It will open your eyes about Hibernate and TopLink and JPA after you checking the codes that will be generated on your own system application.
    http://www.netbeans.org/download/flash/netbeans_6_gui_builder/netbeans_6_gui_builder.html

  • How to configure Sesion Factory in Hibernate to implement getCurrentSession

    Hi,
    I am new in Hibernate and I am using an application where I need to improve the performance while uploading the users through a utility. While analyzing the system, I found that, to insert a single user there were around 8 hits are made to DB to get the information and based on that finally it inserts the user. The strange thing I have noticed is that for every hit, a new DB connection is opened in code using the snippet getHibernateTemplate().getSessionFactory().openSession();
    However, the connection is getting closed in finally block. But I think instead of using Open Connection; getCurrentSession can save time.
    Can any one suggest whether I am on right track?
    Also, when I have tried to use getCurrentSession I have simply replaced "getHibernateTemplate().getSessionFactory().openSession();" with "getHibernateTemplate().getSessionFactory().getCurrentSession();" from everywhere in code.
    But when I tried to run the Utility I got some Hibernate Exception stating "No Hibernate Session bound to thread, and configuration does not allow creation".
    Could anyone suggest do I need to configure anything else in my applicationcontext.xml to use the getCurrentSession() method.
    Thanks in advance.

    the method getCurrentSession() should be done using Singleton factory method so that you have only one connection per application. You can implement something like this as coded below:
    import java.io.File;
    import javax.naming.InitialContext;
    import org.apache.log4j.Logger;
    import org.hibernate.HibernateException;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
    import org.hibernate.cfg.Environment;
    * @author hennebrueder This class garanties that only one single SessionFactory
    *         is instanciated and that the configuration is done thread safe as
    *         singleton. Actually it only wraps the Hibernate SessionFactory.
    *         When a JNDI name is configured the session is bound to to JNDI,
    *         else it is only saved locally.
    *         You are free to use any kind of JTA or Thread transactionFactories.
    public class InitSessionFactory {
          * Default constructor.
         private InitSessionFactory() {
          * Location of hibernate.cfg.xml file. NOTICE: Location should be on the
          * classpath as Hibernate uses #resourceAsStream style lookup for its
          * configuration file. That is place the config file in a Java package - the
          * default location is the default Java package.<br>
          * <br>
          * Examples: <br>
          * <code>CONFIG_FILE_LOCATION = "/hibernate.conf.xml".
          * CONFIG_FILE_LOCATION = "/com/foo/bar/myhiberstuff.conf.xml".</code>
         private static String CONFIG_FILE_LOCATION = "<Path to hibernate.cfg.xml>";
         /** The single instance of hibernate configuration */
         private static final Configuration cfg = new Configuration();
         /** The single instance of hibernate SessionFactory */
         private static org.hibernate.SessionFactory sessionFactory;
          * initialises the configuration if not yet done and returns the current
          * instance
          * @return
         public static SessionFactory getInstance() {
              if (sessionFactory == null)
                   initSessionFactory();
              return sessionFactory;
          * Returns the ThreadLocal Session instance. Lazy initialize the
          * <code>SessionFactory</code> if needed.
          * @return Session
          * @throws HibernateException
         public Session openSession() {
              return sessionFactory.getCurrentSession();
          * The behaviour of this method depends on the session context you have
          * configured. This factory is intended to be used with a hibernate.cfg.xml
          * including the following property <property
          * name="current_session_context_class">thread</property> This would return
          * the current open session or if this does not exist, will create a new
          * session
          * @return
         public Session getCurrentSession() {
              return sessionFactory.getCurrentSession();
          * initializes the sessionfactory in a safe way even if more than one thread
          * tries to build a sessionFactory
         private static synchronized void initSessionFactory() {
               * [laliluna] check again for null because sessionFactory may have been
               * initialized between the last check and now
              Logger log = Logger.getLogger(InitSessionFactory.class);
              if (sessionFactory == null) {
                   try {
                        File f = new File(CONFIG_FILE_LOCATION);
                        cfg.configure(f);
                        String sessionFactoryJndiName = cfg
                        .getProperty(Environment.SESSION_FACTORY_NAME);
                        if (sessionFactoryJndiName != null) {
                             cfg.buildSessionFactory();
                             log.debug("get a jndi session factory");
                             sessionFactory = (SessionFactory) (new InitialContext())
                                       .lookup(sessionFactoryJndiName);
                             //sessionFactory = new AnnotationConfiguration().configure(System.getProperty("user.dir") + "\\" + CONFIG_FILE_LOCATION).buildSessionFactory();
                        } else{
                             log.debug("classic factory");
                             sessionFactory = cfg.buildSessionFactory();
                   } catch (Exception e) {
                        System.err
                                  .println("%%%% Error Creating HibernateSessionFactory %%%%");
                        e.printStackTrace();
                        throw new HibernateException(
                                  "Could not initialize the Hibernate configuration");
         public static void close(){
              if (sessionFactory != null)
                   sessionFactory.close();
              sessionFactory = null;
    }Test it and let me know.

  • Article comparing TopLink and Hibernate

    I recently had a chance to develop two very similar J2EE applications. In one application I used TopLink. In the other application I used the open-source Hibernate persistence framework.
    I wrote a brief high-level article documenting my experiences. The URL is:
    http://www.calextech.com/articles/HibernateToplink.pdf
    I'd appreciate any comments.

    Hello, I was wondering if you have any idea on how to use JDeveloper IDE effectively while working with HIBERNATE.
    Or is the notion that most of the 'HIBERNATE stuff', like generating mapping files, etc are well done outside the scope of the IDE.
    We are currently evaluating HIBERNATE, and will really appreciate your help in this regard.

  • TopLink versus Hibernate?

    Hello, everyone:
    We're in the midst of deciding between Hibernate (which we
    currently use) and TopLink (which looks very good).
    I've checked Google, but I did not find a great deal of
    useful information. Can anyone point me to a good link?
    Thanks!
    Regards,
    Oswald

    Hello, everyone:
    We're in the midst of deciding between Hibernate (which we
    currently use) and TopLink (which looks very good).
    I've checked Google, but I did not find a great deal of
    useful information. Can anyone point me to a good link?
    Thanks!
    Regards,
    Oswald

  • HELP - Hibernate vs Toplink!!!

    Hello Everybody,
    I have some questions related with Hibernate vs Toplink.
    1- To obtain that driver JDBC it gives back the amount of rows affected in each one of updates of a lot that is executed in batch. Hibernate to implement the optimistic lock, adds to each consultation a "WHERE >" where it compares the VERSION of the object in memory with the field VERSION of tuple corresponding in the DB. If it detected that rows were updated "0" it interprets that another user modified that object before and shoots an exception of Concurrence. When batch is used to execute a lot of consultations, driver gives back a vector like result. Each position of this vector this destining to indicate the amount of updates that they became in each consultation of the lot. The problem is that when using PreparedStatement (that is what Hibernate uses to execute the queries) the vector gives back to "-2" in all positions without concerning the real amount that were affected. The affected fact that driver it gives back to "-2" and not real amount
    it for a consultation causes that Hibernate cannot determine if were or not a concurrence problem. We cannot modify Hibernate so that it knows to interpret the "-2" given back by driver because it would not be sufficient to determine if the version were or not modified. The safe SOLUTION to this problem would be that driver it gives back to Hibernate the affected real amount to him in each one of the positions. This is what Hibernate hopes. We can see the execution batch that implements Hibernate in org.hibernate.jdbc.AbstractBatcher>>executeBatch of the
    distribution of Hibernate. Could be solve this problem with Toplink?
    2-Security by dominion. How we would take label security with Hibernate? I know it is possible much better with Toplink but what about Hibernate.
    3-Multiple mappings with Hibernate. Hibenate makes alternative mappings and for this reason it raises more of the necessary thing affecting the performance. Although with them we solved several problems of performance turn out uncomfortable to maintain to them. How we can improve it. Could be solve this problem with Toplink?
    Best Regards,
    Seba.

    1- This issue is down in the driver, and we have seen it before. We have worked with the driver team to come up with a solution in the 10.1.3.1 release. The client would use the Oracle9Platform and call this method session.getLogin().getPlatform().setUsesNativeBatchWriting(true); This will cause TopLink to call special API on the Oracle Drivers to do what is expected of locking and batching together.
    2- I assume that you are referring to OLS and VPD. TopLink supports this, but we will need more information to help you further.
    3- Not sure what you mean here... In TopLink you can map multiple mappings to the same entity. is that what you are referring to?

  • Hibernate's dual-layer cach and TopLink's caching strategy

    Dear members,
    I understand that caching between hibernate and toplink is implemented (or utilized) differently. Hibernate seems to have 'dual-layer caching' (which may imply they have two layers of cache) whereas TopLink has session cache and shared cache. The way I see it, they seem to be aiming for the same thing. Are there any differences between (obviously there are, only that I do not know them) those two caching architectures, and how different are they?
    Howard

    Yes there are differences :) For details check out
    TopLink vs Hibernate... revisited... again :)
    and
    Indirection - how are references resolved after session has been closed?

  • Lazy loading differences Toplink vs. Hibernate - plz. explain

    I'm in the process of evaluating both Toplink and hibernate as potential ORM framework to use for a project I'm currently involved in.
    My question is about how Toplink resolves lazily loaded associations. In hibernate I have to perform a query inside a transactional context boundary, like:
    Session s = SessionFactory.getSession();
    s.beginTransaction();
    ... your query logic here
    s.getTransaction().commit();When the query involves associations which are declared as lazily loadable, trying to invoke these associations after the transaction boundary has been closed, results in an exception. This differs from Toplink (my JUnit testcase breaks for Hibernate if I set the DAOFactory to return hibernate enabled DAO's) and I'm wondering why?
    I'm guessing this has something to do with how Toplink manages its clientsession, but would like to get some confirmation about this. It looks like as-long as the thread of execution is running I can resolve associations using Toplink, but not when I use Hibernate.
    This brings me to yet another question - what's considered best practices in Toplink regarding session disposal. Should I do something myself, or let the garbage collector take care of it?

    I'm not too sure here, but I think it's because TopLink has a "long running" ServerSession. When you do lazy initialization outside a clientsession it is for read only purposes and it will use the centrally managed ServerSession (and cache). I'm still trying to figure out the exact relationships here, som I'm not too sure. :) Hibernate does not have a centrally shared cache, and will not be able to instantiate objects if the session is closed (for each session, objects are instantiated from it's data cache).
    As for handling resources and closing/opening, use the Spring/TopLink integration. It will handle it for you and give you heaps of convenience methods that uses some clever tricks to decide if it should fetch objects with Session or UnitOfWork. It will also do some good Exception handling built into Spring.

  • When Oracle TopLink will have a certified JPA compliant implementation?

    FAQ at: http://www.oracle.com/technology/products/ias/toplink/jpa/resources/faq.html#4
    says: "Applications developed against TopLink Essentials using JPA will run on Oracle TopLink when its JPA implementation is certified as compliant."
    10.1.3.1.0 Release note at http://www.oracle.com/technology/products/ias/toplink/doc/10131/relnotes/rel_notes.htm says: "The TopLink 10g (10.1.3.1.0) supports all but a small subset of the functionality specified in the EJB 3.0 specification."
    I cannot find details about "small subset" not supported.
    Would be nice to have an article about how to use JPA standard API with proprietary TopLink and then how look like the code that need to use the proprietary TopLink extension in some cases.

    Our upcoming Oracle TopLink 11 release has JPA compliance and a rich set of extensions as one of its primary goals. This will make the full functionality of TopLink available through JPA including custom annotations and the ability to integrated TopLink's existing XML.
    This release will be previewed soon allowing you early access to this functionality. This full JPA with extensions functionality is also what we will be contributing to the Eclipse Java Persistence Platform Project (EclipseLink)
    Doug

  • Is "Process scoped identity" the same thing as TopLink shared cache?

    Bumped into this thread on my investigation of ORM solutions:
    http://forum.hibernate.org/viewtopic.php?t=939623&highlight=toplink
    What I would like to know is whether "Process scoped identity" as Gavin King puts it, is the same as TopLink shared cache and if so, whether this could cause deadlocks?
    Quote:
        All the docs for Hibernate assume that you are working in a multi-user system,
        where process scoped identity is an absolute no-no - you would require
        synchronization on entity instances, which is guaranteed to result in deadlocks,
        since there is no possible "natural" order in which to obtain locks.

    Yes, process scoped identity is basically what TopLink's shared server session cache is offering. Having shared instances is a huge benefit for performance and is most noticeable with read-only and read-mostly data types shared across users.
    Yes, we do need to have locking to ensure that changes are safely written into the shared instance and that transactionally isolated (UnitOfWork) copies are safely made in a row consistent fashion. Although I cannot comment on Hibernate's implementation I assume that whatever object type they use in their shared (L2) cache offers the same concurrency protection to ensure that users get consistent data and that concurrent writes do not corrupt the cached object structure.
    I guess the only real difference is the object type cached. TopLink cached your business object and Hibernate caches a custom object representing the state of you object. Both need to ensure proper locking for concurrency protection but TopLink does not need to rebuild an instance for each client session unless wanted/needed.
    Doug

  • Exception in JPA (NoClassDefFoundError: org/hibernate/AnnotationException)

    Hi,
    I´m having a serious problem when using JPA. I´m using Weblogic Server 10 and developing in Weblogic Workshop Studio. When I start the WLS in Workshop, all works fine, but when I use the "publish" over my WLS Server in Workshop because I change any class in the project (and I need to republish the project to send the changed class to WLS), the following error is reported when I try to use the JPA:
    Caused by: javax.ejb.EJBTransactionRolledbackException: EJB Exception: : java.lang.NoClassDefFoundError: org/hibernate/AnnotationException
    at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:353)
    at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
    at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1265)
    at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:150)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:884)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:186)
    Why the AnnotationException class is no more found after a publish in a started Weblogic Server ?
    Thanks in advance,
    Sergio Stateri Jr.
    [email protected]

    Sergio,
    there are at least three implementation for JPA available: OpenJPA, TopLink, and Hibernate. The first two are or can easily installed in WLS. If you intend to use Hibernate as the persistence provider you should ensure that all libraries are in the class path of your application.
    --olaf                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for