Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7564233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:51:33+00:00 2026-05-30T13:51:33+00:00

My application-datasource.xmls is below my problem is I don’t want to provide the user

  • 0

My application-datasource.xmls is below my problem is I don’t want to provide the user name and password in this
context file I want to get the username and password at the runtime when user logs in but I don’t know how
to do this.

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

    <tx:annotation-driven />
    <!-- DataSource has been Lazily initialized, set lazy-init to false in production -->

    <bean id="datasource"
    class="com.mchange.v2.c3p0.ComboPooledDataSource" lazy-init="true" destroy-method="close">
    <!-- Tracker created for connection problem: https://sourceforge.net/tracker/?func=detail&aid=3176467&group_id=25357&atid=38369 0-->
    <property name="driverClass" value="com.ibm.as400.access.AS400JDBCDriver" />
    <property name="jdbcUrl" value="${url}" />
    <!--<property name="user" value="${username}" />
    <property name="password" value="${password}" />-->

    <!-- Pool Size Properties follow -->
    <property name="minPoolSize" value="0"/> <!-- Minimum no. of pooled connections -->
    <property name="initialPoolSize" value="1" /> <!-- Initial no. of pooled connections (>minimum)[optional] -->
    <property name="maxPoolSize" value="2"/> <!-- Maximum no. of pooled connections (>minimum) -->
    <property name="acquireIncrement" value="1"/> <!-- Connections to be added every time the need arises -->

    <!-- Connection Establishment Strategy follows -->
    <property name="acquireRetryAttempts" value="5" /> <!-- Retry Attempts on Database connection failure -->
    <property name="acquireRetryDelay" value="1000"/> <!-- Milliseconds between re-tries -->
    <property name="breakAfterAcquireFailure" value="true" /> <!-- Aggressively break DataSource on connection failure -->

    <!-- Prepared Statement pooling -->
    <property name="maxStatements" value="300"/> <!-- Value ~= maxPoolSize * no. of (frequently used)stored procedures -->
    <property name= "maxStatementsPerConnection" value="15" /> <!-- Statement caching per connection for improved performance -->

    <!-- Connection Age related settings -->
    <property name="maxIdleTime" value="300" /> <!-- Seconds for a connection to remain idle before being closed -->
    <property name="unreturnedConnectionTimeout" value="300" /> <!-- Wait for number of seconds for application to release a connection -->

    <property name="idleConnectionTestPeriod" value="30000"/> <!-- Test for idle connections(In milliseconds) -->
    <property name= "autoCommitOnClose" value="true" /> <!-- For ensuring all transactions to commit/rollback on close -->
    <property name="debugUnreturnedConnectionStackTraces" value ="true" />
    <!-- Ignored overrides -->

    <!-- Used for connection testing during startup -->
    <!--property name="testConnectionOnCheckin" value="true" /--> <!-- Test for connection validity asynchronously -->

    <!--property name="initialPoolSize" value="1" /--> <!-- Initial no. of pooled connections (>minimum)[optional] -->
    <!--property name="idleConnectionTestPeriod" value="30000" /> In milliseconds(Overridden) -->
    <!--property name="maxConnectionAge" value="1800" /--> <!-- Life in seconds for any connection(busy/idle) before being deleted -->
    <!--property name="numHelperThreads" value="3" /--> <!-- Perform JDBC operations asynchronously -->

    <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="persistenceUnitName" value="persistence" />
    <property name="persistenceXmlLocation" value="classpathersistence.xml" />
    <property name="dataSource" ref="datasource" />
    <property name="loadTimeWeaver">
    <bean class="org.springframework.instrument.classloading .InstrumentationLoadTimeWeaver" />
    </property>
    <property name="jpaVendorAdapter" ref="vendorAdapter" />
    </bean>

    <bean id="vendorAdapter"
    class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
    <property name="databasePlatform" value="${dialect}" />
    <property name="showSql" value="${show_sql}" />
    <property name="generateDdl" value="false" />
    </bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionM anager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor" />
<bean class="org.springframework.dao.annotation.Persiste nceExceptionTranslationPostProcessor"/>
</beans>

Some sites suggests to use the UserCredintialDataSource but it not works actually I want to refresh the entitymanagerfactory so it can makes the entity objects using the new connection in my current scenario it gives the error cannot open the connection while fetching the data.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:51:34+00:00Added an answer on May 30, 2026 at 1:51 pm

    The EntityManagerFactory is global so what you are proposing will not work very well. If you refresh (ie, recreate) the EnitytManagerFactory, that will affect the entire application, not just the current request/thread/user. If you want truly to have have different database credentials for each user, Hibernate is not your best choice. You would essentially have to create a unique EntityManagerFactory for each session which would generate a lot of performance overhead and memory duplication. You can’t use connection pools either, since you need to open a new connection for each user anyway.

    My advice, re-think your requirements and your architecture. If you can’t get away from user-credentials in the database and you must use Hibernate, then you will have to take a significant hit in performance, memory and complexity as you need to open and close new entitymanagerfactories for each user session.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an installer for an application. The user gets to select a datasource
I'm building an installer for an application. The user gets to select a datasource
I have the following ColdFusion 9 code: <cfloop from=1 to=#arrayLen(tagArray)# index=i> <cfquery name=qryGetSPFAQs datasource=#application.datasource#>
In an application I want to use my own implementation of javax.sql.DataSource that extends
In our application when we create the Datasource, we select the Database Name DB2
I have spring application and using property file want to read the values from
The datasource used by my web application connects using the ROOT user. The ROOT
I'm using DevExpress LookUpEdit control in my application. I want to set the datasource
This an C# WPF application with SQL CE as DataSource: I have a DataTable
Situation: WPF application, .NET4, DataSource (MS SQL Server 2008) created with the designer Problem:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.