-->
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.  [ 5 posts ] 
Author Message
 Post subject: Does HibernateToolTask get a new set of env vars?
PostPosted: Wed May 20, 2009 1:39 pm 
Newbie

Joined: Wed May 20, 2009 12:41 pm
Posts: 3
Hi
I have a workaround for this but I thought it was interesting and I haven't been able to pinpoint the exact cause.

First off, we use ntlmauth.dll for authentication in most of our DBs - not all of them. I'm using Eclipse on a Windows XP PC. I am working on legacy code where the ntlmauth.dll has been put in various different directories in different projects. I will not be able to put ntlmauth.dll in \Windows\System32. I don't particularly want to move all these dlls. The hibernate jars are from plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib.

Concentrating on one of the projects, I have an Ant build file; the relevent parts are below. I have also put my hibernate.cfg.xml at the bottom. The ntlmauth.dll is in <project>\dll directory. When I try to build the hbm2ddl from a command prompt it complains that it can't find the Native SSPI library. If I move the ntlmauth.dll into the root of the project where the build.xml is, the build works fine (this is the workaround but for the rest of this discussion I will leave the dll where it was in the dll directory).

If I open the command prompt and do this from the project directory:
>ant hibernate_schema
it will complain and I can see from the echo path and exec set that the dll directory is not there.
[echo] path=C:\sybase\ODBC;C:\sybase\OCS-12_5\lib3p;C:\sybase\OCS-1 etc
[exec] PATH=C:\sybase\ODBC;C:\sybase\OCS-12_5\lib3p;C:\sybase\OCS-1 etc

Now I do the following on the command line:
>set PATH=dll;%PATH%
>ant hibernate_schema
and it works. Cool, the path echo shows the dll directory at the beginning of the path.
[echo] path=dll;C:\sybase\ODBC;C:\sybase\OCS-12_5\lib3p;C:\sybase\OCS-1 etc
[exec] PATH=dll;C:\sybase\ODBC;C:\sybase\OCS-12_5\lib3p;C:\sybase\OCS-1 etc

OK. Now I also have an Ant build config in Eclipse which basically builds the same build.xml, except I have configured an extra Environment variable like this: PATH=dll;${env_var:PATH}.
If I run it, the build fails with the same complaint. However, the echo path shows that the dll directory is there.
[echo] path=dll;C:\sybase\ODBC;C:\sybase\OCS-12_5\lib3p;C:\sybase\OCS-1 etc
[exec] PATH=dll;C:\sybase\ODBC;C:\sybase\OCS-12_5\lib3p;C:\sybase\OCS-1 etc

So the big question is why does the Eclipse build fail even though the path has the dll directory in it? Is it because HibernateToolTask is opening a new "shell" when connecting to the DB and using default Windows environment? Or is it when Ant is invoking HibernateToolTask?
(Or am I missing something obvious? :-)

Hope someone can explain it
Thanks
Chris

Here's the relevent bits of the build.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<project name="DatabaseExtract" default="junit" basedir=".">
   <property name="src.dir" value="src" />
   <property name="src.main.dir" value="${src.dir}/main" />
   <property name="src.main.java.dir" value="${src.main.dir}/java" />
   <property name="src.main.resources.dir" value="${src.main.dir}/resources" />
   <property name="src.main.resources.conf.dir" value="${src.main.resources.dir}/conf" />
   <property name="src.main.resources.lib.dir" value="${src.main.resources.dir}/lib" />
   
   <property environment="envi"/>
   <echo message="path=${envi.PATH}"/>
   <exec executable="cmd"><arg value="/c"/><arg value="set"/></exec>

   <path id="hibernate.class.path" description="Hibernate class path">
      <fileset dir="${src.main.resources.lib.dir}">
         <include name="*.jar" />
      </fileset>
      <dirset dir="${basedir}" />
   </path>
   ...
   <taskdef name="hibernatetool"
      classname="org.hibernate.tool.ant.HibernateToolTask"
      classpathref="hibernate.class.path"/>
   ...
   <target name="hibernate_schema" description="Generates Hibernate Schema from mappings.">
      <hibernatetool destdir="${src.main.java.dir}">
         <configuration configurationfile="${src.main.resources.conf.dir}/hibernate.cfg.xml" />
         <hbm2ddl drop="true" create="true"/>
      </hibernatetool>
   </target>
   ...
</project>

and this is the hibernate.cfg.xml, with the server name scrubbed out:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property> 
        <property name="hibernate.connection.url">jdbc:jtds:sqlserver://xxxxxxxx;databaseName=TestDB;Integrated Security=true;</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
        <property name="current_session_context_class">thread</property>
        <property name="hibernate.show_sql">true</property>
        <mapping resource="com/test/log/model/LogHeader.hbm.xml" />
        <mapping resource="com/test/log/model/LogEvent.hbm.xml" />
    </session-factory>
</hibernate-configuration>

and finally a stack trace:
Code:
[hibernatetool] [2009-05-20 18:25:48,920] [INFO ][DriverManagerConnectionProvider] - using driver: net.sourceforge.jtds.jdbc.Driver at URL: jdbc:jtds:sqlserver://xxxxxxxx;databaseName=TestDB;Integrated Security=true;
[hibernatetool] [2009-05-20 18:25:48,920] [INFO ][DriverManagerConnectionProvider] - connection properties: {}
[hibernatetool] [2009-05-20 18:25:48,920] [DEBUG][DriverManagerConnectionProvider] - opening new JDBC connection
[hibernatetool] [2009-05-20 18:25:49,108] [ERROR][SchemaExport] - schema export unsuccessful
[hibernatetool] java.sql.SQLException: I/O Error: SSO Failed: Native SSPI library not loaded. Check the java.library.path system property.
[hibernatetool]    at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:614)
[hibernatetool]    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:344)
[hibernatetool]    at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
[hibernatetool]    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:182)
[hibernatetool]    at java.sql.DriverManager.getConnection(DriverManager.java:525)
[hibernatetool]    at java.sql.DriverManager.getConnection(DriverManager.java:140)
[hibernatetool]    at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
[hibernatetool]    at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:28)
[hibernatetool]    at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
[hibernatetool]    at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
[hibernatetool]    at org.hibernate.tool.hbm2x.Hbm2DDLExporter.doStart(Hbm2DDLExporter.java:164)
[hibernatetool]    at org.hibernate.tool.hbm2x.AbstractExporter.start(AbstractExporter.java:95)
[hibernatetool]    at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:40)
[hibernatetool]    at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
[hibernatetool]    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[hibernatetool]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatetool]    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[hibernatetool]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[hibernatetool]    at java.lang.reflect.Method.invoke(Method.java:585)
[hibernatetool]    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[hibernatetool]    at org.apache.tools.ant.Task.perform(Task.java:348)
[hibernatetool]    at org.apache.tools.ant.Target.execute(Target.java:357)
[hibernatetool]    at org.apache.tools.ant.Target.performTasks(Target.java:385)
[hibernatetool]    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[hibernatetool]    at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[hibernatetool]    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[hibernatetool]    at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[hibernatetool]    at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[hibernatetool]    at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[hibernatetool]    at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
[hibernatetool] Caused by: java.io.IOException: SSO Failed: Native SSPI library not loaded. Check the java.library.path system property.
[hibernatetool]    at net.sourceforge.jtds.jdbc.TdsCore.sendMSLoginPkt(TdsCore.java:1889)
[hibernatetool]    at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:587)
[hibernatetool]    ... 29 more


Top
 Profile  
 
 Post subject: Re: Does HibernateToolTask get a new set of env vars?
PostPosted: Fri May 22, 2009 2:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
We don't spawn a process from within eclipse so make sure that path is set from where you launch eclipse.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Does HibernateToolTask get a new set of env vars?
PostPosted: Fri May 22, 2009 6:10 am 
Newbie

Joined: Wed May 20, 2009 12:41 pm
Posts: 3
So you're saying my Ant environment is lying to me? :-)

I mean this part when run from Eclipse:
<property environment="envi"/>
<echo message="path=${envi.PATH}"/>
[echo] path=dll;C:\sybase\ODBC;C:\sybase\OCS-12_5\lib3p;C:\sybase\OCS-1 etc


Thanks


Top
 Profile  
 
 Post subject: Re: Does HibernateToolTask get a new set of env vars?
PostPosted: Fri May 22, 2009 9:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Wombleydude wrote:
So you're saying my Ant environment is lying to me? :-)

I mean this part when run from Eclipse:
<property environment="envi"/>
<echo message="path=${envi.PATH}"/>
[echo] path=dll;C:\sybase\ODBC;C:\sybase\OCS-12_5\lib3p;C:\sybase\OCS-1 etc


Thanks


ah you you run eclipse from within eclipse ?

Well, for that I don't know the answer. I would assume setting Path on the Ant launch config should be enough.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Does HibernateToolTask get a new set of env vars?
PostPosted: Fri May 22, 2009 10:00 am 
Newbie

Joined: Wed May 20, 2009 12:41 pm
Posts: 3
Yeah it works outside of Eclipse but fails when invoking the Ant build from within Eclipse. Sounds like it is an Ant problem so I should take this question there. Tomorrow maybe :)

Thanks


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

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.