-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Just pass a custom properties map to the PU
PostPosted: Mon Dec 14, 2009 1:41 am 
Beginner
Beginner

Joined: Mon Dec 14, 2009 12:26 am
Posts: 23
I'm working with plain 'ol J2SE and using Hibernate via JPA2, but at least there I've found that passing a custom properties map to the persistence unit when I init it seems to be the easiest way to go.

I use the classloader to find my default properties map for the connection, containing all the usual hibernate props. I slurp that into Properties.load(InputStream) to create the default properties map I'll be using. The user is prompted for authentication by the app before initing the PU, and a new properties map is created with the old one as its base and the username and password attributes inserted into it. Oversimplified, something like:

Code:
AuthDialog someDialog = new AuthDialog();
someDialog.setVisible(true);
if (!someDialog.isCancelled()) {
  Properties connProps = new Properties( dflConnProps );
  connProps.setProperty("hibernate.connection.username", someDialog.getSuppliedUsername());
  connProps.setProperty("hibernate.connection.password", someDialog.getSuppliedPassword());
  EntityManagerFactory f = new Persistence.createEntityManagerFactory("PUname", connProps);
}


... though of course in the real app I don't jumble DB and gui code together like this, it's all cleanly separated and the DB work runs on a background thread.

This way, I don't have to mess about with custom connection providers. I don't know how well this applies to an appserver managed environment, though...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.