| Sign In/My Account | View Cart |
| Article: |
Hibernate for Java SE | |
| Subject: | still use Spring & JNDI | |
| Date: | 2005-11-17 14:00:29 | |
| From: | brondsem | |
| I do something similar, but continue to use Spring (it wires nearly everything together, so I must, and it's good to use) and JNDI to get a handle for my datasource. No changes to my code. IIRC, all I had to do was change my spring applicationContext.xml to use "classpath:hibernate.cfg.xml" as the value of "configLocation" (on my org.springframework.orm.hibernate3.LocalSessionFactoryBean), put the same hibernate.cfg.xml file on my classpath when running my j2se code, and provide the JNDI environment and datasource with simple-jndi (from http://www.osjava.org/simple-jndi/) instead of Tomcat. I'd be happy to provide more details if anyone wants; configuring simple-jndi took me a little while. | ||
Showing messages 1 through 2 of 2.
public class MyDataLoader {
protected AbstractApplicationContext ctx;
public static void main(String[] args) {
new MyDataLoader(args).load();
}
public MyDataLoader(String[] appContextFiles) {
super();
ctx = new FileSystemXmlApplicationContext(appContextFiles);
}
...
}
java.naming.factory.initial=org.osjava.sj.SimpleContextFactory
org.osjava.sj.root=file:///c:/Documents and Settings/myUserID/test-jndi/jndi-entries
org.osjava.sj.delimiter=/
org.osjava.sj.colon.replace=!
type=javax.sql.DataSource
driver=net.sourceforge.jtds.jdbc.Driver
url=jdbc:jtds:sqlserver://host:1433/databaseName;SelectMethod=cursor
user=myUsername
password=myPassword
Thanks.