How to select a Hibenrate configuration file for web application/junit?

Dear all,
I am using hibernate for a web application.
I have two configuration files: one ("hibernate-jta.cfg.xml") uses a data source and the other ("hibernate.cfg.xml") directly uses jdbc.
private static String CONFIG_FILE = "hibernate-jta.cfg.xml"; private static String CONFIG_FILE_WITHOUT_DATASOURCE = "hibernate.cfg.xml";
When I deplyed my applcation to an application server, I need to use the first one. When I run junit test, I need to use the second one.
How can I design a mecanism to switch between the two configuration files according the the case: web application or java stand alone application?
Configuration cfg = new Configuration(); cfg.configure(CONFIG_FILE);
Thanks.
Pengyou

My solution is to add a new public method "initFactoryForJunit() " in the Static singleton.
In the junit test, this method will be invoked in order to load a second configuration file.
public class ThreadsafeSessionFactory {
     private static Logger log = Logger
               .getLogger(ThreadsafeSessionFactory.class);
     private static String CONFIG_FILE = "hibernate-jta.cfg.xml";
     private static String CONFIG_FILE_FOR_JUNIT = "hibernate.cfg.xml";
     private static final Configuration cfg = new Configuration();
     private static org.hibernate.SessionFactory sessionFactory;
     public static SessionFactory getInstance() {
          log.info("getInstance()");
          if (sessionFactory == null) {
               ThreadsafeSessionFactory.initFactory();
          return sessionFactory;
     /*public synchronized Session openSession() {
          log.debug("openSession()");
          return sessionFactory.getCurrentSession();
     public synchronized Session getCurrentSession() {
          log.debug("getCurrentSession()");
          return sessionFactory.getCurrentSession();
     private static void initFactory() {
          log.debug("initFactory()");
          if (sessionFactory == null) {
               try {
                    Configuration cfg = new Configuration();
                    cfg.configure(CONFIG_FILE);
                    String factoryJndiName = cfg
                              .getProperty(Environment.SESSION_FACTORY_NAME);
                    if (factoryJndiName != null) {
                         log.debug("using jndi factory");
                         cfg.buildSessionFactory();
                         sessionFactory = (SessionFactory) (new InitialContext())
                                   .lookup(factoryJndiName);
                    } else {
                         log.info("using default factory");
                         sessionFactory = cfg.buildSessionFactory();
                         log.info("after using default factory");
               } catch (Exception ex) {
                    ex.printStackTrace();
                    log.error("failed creating session factory");
                    throw new HibernateException(
                              "initFactory(): failed initializing configuration");
     public static void initFactoryForJunit() {
          log.debug("initFactory()");
          if (sessionFactory == null) {
               try {
                    Configuration cfg = new Configuration();
                    cfg.configure(CONFIG_FILE_FOR_JUNIT);
                    String factoryJndiName = cfg
                              .getProperty(Environment.SESSION_FACTORY_NAME);
                    if (factoryJndiName != null) {
                         log.debug("using jndi factory");
                         cfg.buildSessionFactory();
                         sessionFactory = (SessionFactory) (new InitialContext())
                                   .lookup(factoryJndiName);
                    } else {
                         log.info("using default factory");
                         sessionFactory = cfg.buildSessionFactory();
                         log.info("after using default factory");
               } catch (Exception ex) {
                    ex.printStackTrace();
                    log.error("failed creating session factory");
                    throw new HibernateException(
                              "initFactory(): failed initializing configuration");
     public static void close() {
          if (sessionFactory != null)
               sessionFactory.close();
          sessionFactory = null;
}

Similar Messages

  • How to create multiple pof configuration files for c# client

    Is there a way to have multiple pof files for c# coherence client?
    Can I create a file called my-pof-config.xml with the following line...
    <pof-config xmlns="http://schemas.tangosol.com/pof">
    <user-type-list>
    <include>assembly://Coherence/Tangosol.Config/coherence-pof-config.xml</include>
         <include>file://pof-config.xml</include>
    and here is what pof-config.xml file look like
    <?xml version="1.0" encoding="UTF-8"?>
    <pof-config xmlns="http://schemas.tangosol.com/pof">
    <user-type-list>
    In my C# visual studio project, this is where I load my-pof-config.xml in app.config
    <coherence>
    <cache-factory-config>coherence.xml</cache-factory-config>
    <cache-config>coherence-cache-config.xml</cache-config>
    <pof-config>my-pof-config.xml</pof-config>
    </coherence>
    and this is what I saw in the log...
    2012-02-23 14:35:35,529 DEBUG Coherence (null) - 2012-02-23 14:35:35.529 level(thread=System.Threading.Thread): Loaded POF configuration from "FileResource(Uri = file://my-pof-config.xml, AbsolutePath = D:\worktrees\ads\mainline\v2\ads\demos_cs\build\my-pof-config.xml)"
    2012-02-23 14:35:35,545 DEBUG Coherence (null) - 2012-02-23 14:35:35.545 level(thread=System.Threading.Thread): Loaded included POF configuration from "EmbeddedResource(Uri = assembly://Coherence/Tangosol.Config/coherence-pof-config.xml, AbsolutePath = assembly://Coherence/Tangosol.Config/coherence-pof-config.xml)"
    2012-02-23 14:35:35,623 DEBUG Coherence (null) - 2012-02-23 14:35:35.623 level(thread=ExtendTcpCacheServiceCSharp:TcpInitiator): Loaded POF configuration from "FileResource(Uri = file://my-pof-config.xml, AbsolutePath = D:\worktrees\ads\mainline\v2\ads\demos_cs\build\my-pof-config.xml)"
    I don't see pof-config.xml is loaded at "Loaded included POF configuration....". How do I get around it so I can load multiple pof configuration files for c# client?

    Hi,
    Not sure about C# but I would suggest try removing file:// from
    <include>file://pof-config.xml</include>and keep pof-config.xml and my-pof-config.xml in the same directory.
    Hope this helps!
    Cheers,
    NJ

  • How to generate an XML Configuration File for EBS Source Type

    Hi,
    We have installed SES, I want to integrate it to enable for searching repository contracts.
    In the sources I have selected oracle.apps.okc.repository.textsearch.server.RepHeaderSearchExpVO.
    For this source I need to specify the Configuration URL.
    Here I need to provide the path for configuration XML file. But before that I need to generate the XML Configuration file.
    Is there any steps on how we can create this XML file.
    like I would want to know how we can create the XML file and on which folder on the server should I be putting it
    Thanks

    Hi there,
    We are running into same issue and need the exact same information. Can someone help with this question on priority?
    Thanks,
    Darshan

  • How do you go about configuring colours for terminal [applications]?

    I figured this might be the best place to ask but I'm not sure.
    I'm using termite, and it has 256 colours predefined. I have always thought that I better define my own colours (override defaults), because the defaults didn't immediately look nice. However, I recently discovered that for example the vim plugin "vim-airlineish" uses colour 55, which matches the screenshots of the plugin - so default colour scheme is assumed. So I'm wondering if this default colour scheme is some kind of global, well known default? And does it perhaps have properties, like: you will most likely find a colour close to the one you want in there, or something else? Is there a name for it?
    http://a.pomf.se/dmahvz.png
    So what I'm really wondering, is: what is the preferred way to configure the colours of console applications?
    Should I leave the default theme as it is and search for the colours I want in this colour scheme?
    Or should I find my own set of colours, and choose amongst these when configuring specific applications? This is what I've been doing so far, and for example, I wanted a greenish theme on my desktop, but the default colour scheme doesn't seem to hold a wide spectrum of green colours. (following picture is from my current colours, which I recently set and which I am not really that satisfied with)
    http://a.pomf.se/rpeisv.png
    Or should I override colours as I need specific colours? An ideal way - but pretty unorderly - to design for instance a colour scheme for coding, would maybe be to use gcolor2/3 to choose any colour that you need, and then put it in the colour scheme. If you could do that easily but you can't really - you have to go through a moderate amount of steps to change one colour, and in the long run of revising, revising, it's just a hassle.
    Thanks in advance for any input you can provide on this!
    -- mod edit: converted img to url tags.  Trilby --
    Last edited by Trilby (2015-05-01 11:41:41)

    You have a few different only paritially overlapping questions here.  How to find a color / is there a name for it:  There are 16 base colors, then a 216 color cube, then 24 grayscale colors.  You can get a bit more about this from a google search - here's one example:
    https://fedoraproject.org/wiki/Features … _Terminals
    There are also countless scripts to print out the 256 colors in a useful way in a terminal.  These scripts are littered all around these forums - just search and you'll find them.
    It is common practice to override the first 16 colors.  There are also countless posts - and I think an entire thread - on these forums devoted to sharing these color schemes.  I believe it is also possible to override any of the other 240 colors, but it is generally not done and I'd advise against it.  These other 240 are generally the ones "assumed".  The first 16 have conventional meaning, but there are no specific shades that should be assumed: 1 is some shade of red or something the user prefers in place of red, 2 is some shade of green, etc.  8-15 are bright versions of 0-7.
    Also, as you search - please find the forum guidelines and only link to larger images.  I converted the images to urls in your post.

  • Multiple log4j.xml files for single application.

    Hi All,
    How to use multiple log4j.xml files for single application?
    I do have a pluggable application modules. ie, If I add a jar I will get some functionalities. Like that i do have many jars.
    Log4j.xml also will be present in that jar only. So if I add multiple jar files like this, I will get multiple log4j.xml files. What should I do?

    Each logger can have its own file I think. Check the log4j documentation.

  • How to create a configuration file for open ldap.

    hi,
    I have installed open ldap on my machine. Now I want to configure it to NetWeaver.
    For this, I started configuration through configtool utility of NetWeaver. While configuring, we need to select or upload configuration file. But now as it is open ldap we need to write our own config file.
    I tried it by selecting dataSourceConfiguration_ads_deep_readonly_db.xml  as a configuratio file. it shows successful test connection but the user which  I have created is not appearing in UME store.
    Does any body having solution for this?
    I am trying to solve this problem from two days. I really appriciate one who will sove this problem

    Well the configuration file you chose does not allow users created in NetWeaver to be created in the LDAP.  That's why it's a "readonly" configuration.  I would guess that you need a custom configuration file specifically for open ldap.
    This should help get you started on a custom configuration file:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/b7/14d43f2dd44821e10000000a1550b0/frameset.htm
    Then again, if the only problem with the .XML file you chose is that you can't write to the LDAP, give the dataSourceConfiguration_ads_writeable_db.xml configuration file a shot.

  • How can I Create a Client Configuration File for RemoteApp and Desktop Connection with Server 2012?

    I have a working RDS RemoteApp site and looking to test out the feature in Windows 7 Control Panel\All Control Panel Items\RemoteApp and Desktop Connections
    I came across this link: Create a Client Configuration File for RemoteApp and Desktop Connection and I believe this is what I need to do first, but these instructions are for
    Server 2008, and I'm running 2012.
    Any suggestions or tips on how I can begin testing this with Server 2012?

    Hi,
    You can manually enter the path to the 2012 feed and it will connect and download the RemoteApps and Desktop connections.
    If you need a sample .wcx file I have posted one here a couple of times.  If you want I will look for it and post a link.
    -TP
    I tried adding my URL's below, these are sample links that work for me right now for when I log into the web page, but neither of these work.  And I'm not sure what I would need to do with or how to create a .wcx file.
    When I type in my URL of: https://connect.mydomain.org/RDWeb, I get redirected to: 
    https://connect.mydomain.org/RDWeb/Pages/en-US/login.aspx?ReturnUrl=/RDWeb/Pages/en-US/Default.aspx

  • How can I get my time machine to allow me to recover files again? After upgrading to OS X, the time machine still backs up the files; but, I'm not able to navigate within the time machine or select any folders or files for restore.

    How can I get my time machine to allow me to recover files again?
    After upgrading MBA to OS X, the time machine still backs up the files; but, I'm not able to navigate within the time machine or select any folders or files for restore.
    I've searched and can not find a solution to the problem that's being encountered.

    Yeap that all makes sense now.
    Do you only have the current backup showing in the TM display?? Won't it fill in the rest?
    Over wireless are you waiting for the indexing to finish.. ??
    Previous backup may not show for a couple of hours.
    Long short of it.. Mavericks version of TM is a pain.
    Sometimes it is easier to completely ignore the TM backup and do the restore manually.
    I have posted the details here. See if this helps.
    Can't access old files on time capsule

  • How to specify a different config file for a weblogic 6.1 server

    Hi,
    I have 2 weblogic startup scripts (startWebLogic.sh and
    startWebLogic_recovery.sh) for the same domain.
    startWebLogic.sh uses config.xml file.
    I would like to use config_recovery.xml as the configuration file for startWebLogic_recovery.sh
    How would I do this ?
    I am using WebLogic Server 6.1 on SunOS 5.8 / HP-UX 11.0.
    Appreciate any help.
    Regards
    Gunaseelan Venkateswaran

    Hello Gunaseelan,
    This is not possible because WLS 6.1 needs a config.xml file, exactly this
    name, to start.
    What you can do is to define a recovery domain, called myrecovery_domain for
    instance, and put the config_recovery.xml, renamed "config.xml".
    Hope this helps,
    Ludovic.
    Developer Relations Engineer
    BEA Support.
    "Gunaseelan Venkateswaran" <[email protected]> a écrit dans le message
    news: 3cd6a324$[email protected]..
    >
    Hi,
    I have 2 weblogic startup scripts (startWebLogic.sh and
    startWebLogic_recovery.sh) for the same domain.
    startWebLogic.sh uses config.xml file.
    I would like to use config_recovery.xml as the configuration file forstartWebLogic_recovery.sh
    >
    >
    How would I do this ?
    I am using WebLogic Server 6.1 on SunOS 5.8 / HP-UX 11.0.
    Appreciate any help.
    Regards
    Gunaseelan Venkateswaran

  • How do I add a PDF file for download to my iWeb page?

    How do I add a PDF file for download to my iWeb page?
    I have created one using Apples Pages program.
    Thanks!

    Hi-
    You need to create a text link to the file...
    On your page, type a word that you want to be the link... then select the word, and in the inspector pane, click the link tab (the arrow on the far right) and check "enable as hyperlink." Then choose "file" from the dropdown menu and a chooser box will open for you to locate the file on your hard drive.
    Choose the file by clicking "open" once it's located. Then the next time you publish, the file will be uploaded and linked to!
    Hope this helps... I think I got all the steps in there!

  • Configuration file for servlets

    Hi, everyone
    I have one problem,I can't solve:
    I want write configuration file for several servlets (by incapsulating my static class Config in DBServlet subclass), but I don't know how can I find this config file in runtime( it will be placed, as I think in root documents directory of web-server).
    I can't use no method of DBServlet and HTTPRequest on its initialization phase (suche methods as getServletContext, getServerName, getServerPort and others), so
    I can't get real path of root documents directory of web-server.
    If I will read this file by URL like "localhost/config.cfg" there will be problem in web-server configuration with access permissions, I think.
    Is there some standard ways to find and read in servlet runtime from file , which is placed in root documents directory of web-server.
    Thanks in advance, Ed

    Ed,
    Your configuration file must be in your CLASSPATH.
    Regards
    Blaise

  • Failed to load the configuration file for the workflow

    Hi experts, yesterday I created and publish custom workflow using SPD from client pc using site administrator account but today its shows error message. I tried creating new test workflows, edit and publish to think it will push a fresh SPD settings
    in working condition and it works pretty right.
    But the thing I noticed after closing SPD Im not able to re-open workflows and it gives the same error message Failed to load the configuration file for the workflow. This issue only happen today since day one  I used SPD and all the time
    Im using the same pc.
    Any ideas will be appreciated.
    Cheers, R2C3 ----------------------------------- starting sharepoint :)

    HI
    Maybe you have permission problem or there is invalid xoml murkup.
    To verify this from SharePoint Designer use the following steps.
    In Office SharePoint Designer, in the folder list, select the plus sign next to Workflows library to expand it
    1.Next select the plus sign of the workflow in question to expand it
    2.Double-click the configuration file (Workflow_name.xoml.wfconfig.xml) to open it
    3.Right-click on the page, and then select Verify well-formed XML
    4.Correct any errors and save the file
    5.Reopen the workflow to test
    Also double check that you are using SPD with the same credentials you created workflow
    Hope this will help.
    Regards,
    Marcin

  • Failed to load configuration file for the workflow

    There are two of us who have full control on our Sharepoint 2013 site. I'm able to create workflows and publish them fine. The other user is able to create workflows, but he gets an error when trying to run them. I  tried opening his workflow and got
    the error "Failed to load configuration file for the workflow."
    Any ideas?

    Hi Carltonw1,
    Based on your description, I recommend to verify the things below:
    Clear the SharePoint Designer cache and then open the workflow.
    Ask the user to open the workflow in SharePoint Designer and check if the workflow contains error.
    Ask the user to create the same workflow and associated with another list to see how it works.
    Check the ULS log for more detailed error message.
    To reproduce this issue, could you please provide the detailed steps in the workflow for further research?
    Thanks,
    Victoria
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Victoria Xia
    TechNet Community Support

  • Configuration file for pkcs11 security provider

    Hi all,
    I'm using Mandriva 2008.0 . In the jdk 1.5.0 documentation, it is given that, the security provider pkcs11 can be configured statically by adding an entry, as shown below, in the java.security file present in the directory jre/lib/security/.
    *# configuration for security providers 1-6 ommitted*
    security.provider.7=sun.security.pkcs11.SunPKCS11 /opt/bar/cfg/pkcs11.cfg
    Where can I get the configuration file (pkcs11.cfg) from? Please direct me how to proceed.
    Thanks.

    Hi,
    I went through that Java SE6 documentation link. It describes the contents of the configuration file for pkcs11. But I couldn't find the information of where can I get the configuration file for pkcs11 security provider from.
    Thanks.

  • Single XML configuration file for all the SSIS packages(including parent and child packages)

    Hi
    I have some 16 ssis packages. source Db and destination Db for these packages are common. I am calling these child packages in a master package.
    I want to use only one XML config file for this master.
    How do i use same for all child packages?
    and can i do it with parent package variable?

    I created a master package with a variable master, and in value i have entered the configuration file path.
    Hi vjp dinu,
    You should create variables in the parent package to pass values to variables in each child package rather than pass the file path of the XML Configurations file of the parent package.
    As Visakh mentioned, you can achieve your goal by creating corresponding variables in the parent package for each child package, and enable Package Configurations for the parent package so that you can control the values through the XML Configurations file
    for the variables of the parent package.
    Supposing there is a variable FilePath in child package 1, a variable ServerName in child package 2, then, we need to create two variables pFilePath, pServerName in the parent package. After configuring the Parent package variable in each child package (e.g.
    mapping pFilePath to FilePath, pServerName to ServerName), you can enable XML Configurations for the parent package, and expose the value property for both pFilePath and pServerName variables. In this way, you can modify the XML Configurations file of the
    parent package and the specified values will passed to the child packages.
    Reference:
    http://microsoft-ssis.blogspot.com/2011/06/passing-variables-from-parent-package.html 
    Regards,
    Mike Yin
    TechNet Community Support

Maybe you are looking for

  • Blue screen of death after Windows 7 update-cant get into safe mode or anything else to fix!Help please?!

    Hi My windows 7 professional did an update 2 days ago as i logged out of windows to go back into os x and since then i get a BSOD when i go into windows which flashes so fast I can't see the error message- -I've tried system repair, restore, image, s

  • Invidia Tesla support in Lightroom?

    Does LR 2.1 take advantage of Invidia's Telsa GPU? Tesla allows offloading computations to the GPU. If yes, has anyone tried a Tesla graphics card?

  • Newbee question!

    hi , supposing i use the following code.. <jsp:useBean id="requestInfo" scope="request" class="RequestBean" >   <jsp:setProperty name="requestInfo" property="*" /> </jsp:useBean>in the above case do all set methods in requestinfo object get called? s

  • Can I setup v9 with 3 buttons to highlight in yellow, pink, orange?

    I'm considering upgrading to Acrobat Pro 9 (I've got an older Pro). I'm only interested if I can do one simple task that any doctor, lawyer, student would want: Have multiple buttons and hotkeys to highlight PDFs in different colors (besides yellow).

  • Testing tools for new web UI & PCUI

    Hi Experts, what are the different testing tools used by you in your engagements especially for testing web applications based on new UI (2006s) and PCUI (5.0). we have a need to automate our testing. thanks RH