Spring TopLink support outside container

I'm setting up an internal workshop at our company to teach and demo TopLink. I'm aiming to focus on TopLink, so I figured I would keep it as simple as possible.
I still want to demo transaction spanning several DAO calls though, and thought I could use the TopLink support in Spring for that. Easier said than done when I'm only running from a simple class' main method...
First I try starting a transaction with Spring, as I thought it would be able to fallback/handle it with a ThreadLocal even though it's not inside a container:
TransactionDefinition transDef = new DefaultTransactionDefinition(
TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus
TransactionStatus transStatus = transManager.getTransaction(transDef);
Which gives:
java.lang.UnsupportedOperationException: SingleSessionFactory does not support managed client Sessions
So I figure, alright, fair enough. All I have to do then is initialise a UoW through spring instead of starting a transaction, and then that will be injected into the TopLinkCallback I'm using in my DAO:
SessionFactory sessionFactory = (SessionFactory) appContext.getBean("sessionFactory");
Session currentSession = SessionFactoryUtils.getSession(sessionFactory, true);
UnitOfWork uow = currentSession.getActiveUnitOfWork();
But nope. The getActiveUnitOfWork() in my TopLinkCallback just returns null. Anyone know how to do this best outside a container? How do I initialise a UoW that Spring will hold on to for me?
Anders,

Hi Anders,
SessionFactory sessionFactory = (SessionFactory)
appContext.getBean("sessionFactory");
Session currentSession =
SessionFactoryUtils.getSession(sessionFactory,
true);
UnitOfWork uow =
currentSession.getActiveUnitOfWork();
But nope. The getActiveUnitOfWork() in my
TopLinkCallback just returns null. Anyone know how to
do this best outside a container? How do I initialise
a UoW that Spring will hold on to for me?
Anders,You're getting the expected behavior. getActiveUnitOfWork returns null outside of a transaction. It won't start one for you--you're going to have to do that before you call it.
If you put your code inside a transaction callback like the following you get an active unit of work.
final ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-toplink.xml");
PlatformTransactionManager txManager = (PlatformTransactionManager) ctx.getBean("transactionManager");
TransactionTemplate template = new TransactionTemplate(txManager);
template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionCallbackWithoutResult callback =     new TransactionCallbackWithoutResult() {
     protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
          SessionFactory sessionFactory = (SessionFactory) ctx.getBean("sessionFactory");
          Session currentSession = SessionFactoryUtils.getSession(sessionFactory, true);
          UnitOfWork uow = currentSession.getActiveUnitOfWork();
          // uow is not null
          // your code goes here
// execute your code in a tx
template.execute(callback);This code runs out of container no problem. I tested it with the petclinic example. Hope this helps.
--Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Spring TopLink Integration Preview Updated

    The preview of the Spring TopLink Integration support has been updated on OTN. Changes are described in the release notes.
    Also check out the OTN article Of Persistence and POJOs: Bridging the Object and Relational Worlds on using TopLink with Spring by Rod Johnson and Jim Clarke.

    You will not have to change any java code when you switch "transaction controller" strategies in your Spring beans.xml file.
    When you talk about "the way you use the UnitOfWork in your code", you're talking about the section in the "Transactions" chapter called "External Transaction Controllers" right? In any case, the differences at the java level, are essentially that you acquire an "active" UnitOfWork (getActiveUnitOfWork) and that you no longer explicitly commit the UnitOfWork.
    Neither of these two differences impacts your use of TopLink within Spring. In Spring, the transaction is always managed by a Spring PlatformTransactionManager so your TopLink code will never call commit, whether you're using an ExternalTransactionController or not. The code will be identical whether you're running in J2SE or J2EE.
    Also, since we expect users to access TopLink either through a TopLinkTemplate or through a TopLinkInterceptor, the Spring container will always "inject" a TopLink Session that is aware of whether or not there is currently an ExternalTransactionController. So, there will be no difference between the behavior of acquireUnitOfWork and getActiveUnitOfWork. Both will behave identically. They will return you the UOW currently associated with the current Spring PlatformTransactionManager. So, there is no environmental dependency here either.
    JIM

  • Spring-TopLink Integration and transparent transaction controller

    Hi,
    I'm new to TopLink and I read the article in the "Mastering J2EE" series about the Spring TopLink integration. I never actually got into Spring before, so I went and checked out the articles and tutorials and then I went back to my exploration of TopLink.
    From what I understood, Spring promises that you wouldn't need to change your code, only your configuration files, if you change your transaction controller from the OR framework transaction controller to a JTA enabled one provided by the AS. But when I read the "Transactions" chapter in the TopLink application developer's guide, it seemed that the way you use the UnitOfWork in your code differs significantly depending on whether you're using an external transaction controller.
    My question is, does this void Spring's promise or is there a work around for that?
    Thanks.

    You will not have to change any java code when you switch "transaction controller" strategies in your Spring beans.xml file.
    When you talk about "the way you use the UnitOfWork in your code", you're talking about the section in the "Transactions" chapter called "External Transaction Controllers" right? In any case, the differences at the java level, are essentially that you acquire an "active" UnitOfWork (getActiveUnitOfWork) and that you no longer explicitly commit the UnitOfWork.
    Neither of these two differences impacts your use of TopLink within Spring. In Spring, the transaction is always managed by a Spring PlatformTransactionManager so your TopLink code will never call commit, whether you're using an ExternalTransactionController or not. The code will be identical whether you're running in J2SE or J2EE.
    Also, since we expect users to access TopLink either through a TopLinkTemplate or through a TopLinkInterceptor, the Spring container will always "inject" a TopLink Session that is aware of whether or not there is currently an ExternalTransactionController. So, there will be no difference between the behavior of acquireUnitOfWork and getActiveUnitOfWork. Both will behave identically. They will return you the UOW currently associated with the current Spring PlatformTransactionManager. So, there is no environmental dependency here either.
    JIM

  • Can I use ADF Logger in non-ADF applicaiton and outside container?

    Hi all,
    I want to use ADF Logger feature in non-ADF applicaiton and outside container. Is that possible?
    Thanks,
    Xianyi.Ye

    I figured out "partially" the problem, I tried to overrid the create method, and for any reason the commit operation wasn´t working.
    I was trying to set a value for a proprety, but it did not work as a wish.
    My intention was.... when an user execute the form. one specific field brings a value.. however I cannot set default value. cause it´ll change sometimes.
    it´s something like this
    protected void create(AttributeList attributeList) {     
    super.create(attributeList);
    setMyProperty(new Number(0));
    do you know how can I figure out this problem?

  • Spring / Toplink Transaction / Commit Issue

    Hi,
    Im working on a spring / toplink integration on my project.
    The problem Im facing has to do with transaction / commits
    Im using a TransactionProxyFactoryBean to encapsulate a BusinessProcess responsible for creating a new Company Instance and its main Office.
    As the 2 entity have to be created atomicly I have setup a PROPAGATION_REQUIRED on the createCompanyAndMainOffice method of the CompanyBusinessProcess.
    The problem is I want to return a session, identified company object and I cant see how to do that correctly.
    I tried and create a sub internal method like internalTXCreate called by createCompanyAndMainOffice, that would be the one transactional, so I get the commit at the end of its execution, returning the working copy with the newly inserted id, and perform a load with its its ID on the session from createCompanyAndMainOffice.
    But it seems that the TransactionalProxyFactoryBean only intercepts calls on the 'entry point' methods... so back to where I started ...
    I check the reference petclinic implementation and the only new* method does mention it returns a non identified BusinessObject which I find a bit disturbing in my case ...
    Any idea on the problem ?
    Thanks for your help,
    Best Regards
    Olivier Cuzacq
    Software Architect
    Groupe Moniteur

    Something like this in createCompanyAndMainOffice should work:
    return (Owner)getTopLinkTemplate().registerObject(new Owner());
    post-commit, the returned Object will be a reference from Toplink shared cache.

  • When will Spring-Toplink integration be officially released in Spring

    I notice from previous emails that Spring-Toplink integration will eventually be part of the Spring framework itself (similair to existing Hibernate, iBatis, JDO integration). Can you tell me when this will occur? What version of Spring is being targeted?
    thankyou,
    Chris

    Chris,
    The work is going on right now to have the work checked in and included in Spring 1.2.
    Doug

  • Presentation layer outside container?

    can we place presentation layer outside container and refer from servlet container? If yes, how are we invoking web.xml from the container?

    Only one level is possible.

  • Does TopLink support arrays of primitive types?

    Does TopLink support arrays of primitive types?

    You must use a collection.
    If you really wanted to you could store the data as an array and use get/set methods to convert between the array and collection, or customize your own ContainerPolicy, however arrays a very inefficent to add/remove from so TopLink only provides support for collections.

  • TopLink support for Stored Functions

    I know that TopLink supports PL/SQL stored procedures. What I haven't been able to figure out is whether or not TopLink also supports functions as well. Is there any way to execute a PL/SQL function using the TopLink APIs? Thanks. -Michael-

    You can find additional information (including examples of usage) on using Stored Functions in the TL Dev Guide: http://download.oracle.com/otn_hosted_doc/toplink/1013/MAIN/_html/qrybas004.htm#BCFBBJBJ

  • Toplink support for weblogic 9

    Hi ,
    Is toplink supported with weblogic 9?If yes,which version?
    There is a thread(on OTN) that speaks about toplink support for weblogic 9.
    Weblogic 9 -TopLink CMP
    Thanks,
    Rajbharat

    Rajbharat,
    We have completed our testing of POJO architectures and the WebLogic Support Matrix now reflects this:
    Doug

  • TopLink support for version 2.0/2.1 of ejbql

    Hello,
    TopLink support ejbql for pojo finders.
    What version of ejbql is supported in toplink 9.0.4.8 : 2.0 or 2.1 ?
    What version of ejbql is supported in future release (10.1.3) of toplink : 2.0 or 2.1 ?
    Regards

    I believe the answer to both is 2.1.
    Doug

  • TopLink support DB2/OS390

    Does TopLink support connecting to DB2/OS390? If so, is it with the standard DB2 selection in Workbench, or will another method be required?
    Thanks

    Sorry, meant to say DB2 on AS/400. We do have a number of customers using TopLink on AS/400 with DB2. I do recall experiencing an issue with the JDBC driver IBM provided though. It would not properly report the meta-data information the Mapping Workbench uses to import schemas. To work around this, we manually entered the table information in one case, and in another case we exported the schema to another platform and imported it through a better JDBC driver. I'm sorry I can't confirm which specifric versions this was for. It is a documented limitation of the IBM JDBC driver however. Other than that, we had no problems at all.
    - Don

  • Does toplink support selecting an interval from a ResultSet ?

    Hi,
    I wonder if Toplink supports selecting an interval of rows before creating Java objects. I think I can do this myself using CursorStream but that would take more time to ignoring created java objects than ignoring items (rows) from query result.
    actually the purpose is to simulate cursor. since a cursor is quite expensice to keep in memory for long time, but still the applications, working with a paging logic, want to select one page of objects each time they make a call to toplink, I need to provide them with this functionality.
    for example there is a retrieve request that would result in 1000 objects. in the first call, they want to retrieve 0-50, in the second call 50-100, and so on.
    ps : I don't let these applications keep a cursor on behald of them on the server.
    thanks.
    Erdem.

    ScrollableCursors support intervals and positioning the result set.

  • Does TopLink support JBoss App Server?

    My company is a software development company. So, we use many application servers for our customers.
    I found that TopLink supports OC4J, WebLogic and WebSphere, but I don't know, Does TopLink support JBoss? I just downloaded TopLink for test yesterday, so, I don't know much about TopLink, but my current project uses JBoss.
    Please give me some suggestion that might help me to refine my project.
    Thank you so much.

    Yes it does and there are customers using JBOSS. TopLink supports any app server and, in fact, doesn't even require an app server -- and compliant JVM will do just fine.

  • Does toplink supports  java 5

    My application uses Java 5. So i want to use my classes in toplink workbench.
    I wan to know whether toplink supports java 5 classes.
    Thanks & Regards

    Yes, As of the 10.1.3.0 release TopLink supports the usage of Java 5 classes.
    Doug

Maybe you are looking for

  • Error in running oracle report on APPS due to print style

    Hi i have an oracle report which displays about 550 rows of data...When i try to run it with oracle apps i selelect landwide but i get an error as the defined style can not print that much amount of rows.Is there any toher style which prints this man

  • Adding a 1TB usb disk to Solaris 10

    Im having a few problems trying to add a 1tb drive to Solaris 10 on a sun blade 2000. It seems to find it ok when i attach it, cfgadm shows it ok usb0/4 usb-storage connected configured ok iostat -En shows it as 2 461gb drives, not a problem really a

  • GLT0 FIELD DOUBT - URGENT

    hi exports i want to take gl account balance GLT0 table? but i've some field month wise like HSL01 (apr), HSL02(may), HSL03(jun) like wise? i want to take credit, debit and balance how can i take wht is the prog. i want to take month wise ? how? my p

  • Encryption in animated gifs?

    I've created an animated gif in Fireworks and am uploading it to a remote server for distribution, and the distribution software at the server end is promting "Your image contains an unknown file encryption. The file encryption type is not recognized

  • Nikon D80 Raw

    Has anyone had any luck importing raw images from a d80 nikon? I have read all the manuals, and they say it works, but it doesnt work on my software thanks Orville