Hibernate and iKVM

Kumaravel Sadras <[email protected]>
Newsgroups gmane.comp.java.ikvm.devel
Message-ID <CAFR7Q1tAnN=84DV9Y3jLMe1+06_DB1YbT1ARd6KhvWpmhwE0eg@mail.gmail.com>
Hi
 I have a sample Java Console application that works against hibernate that
uses a mysql connection jar file.

I am trying to make it work in .NET. This is a proof of concept.

 I converted all dependent jar file dlls using ikvmc

My .NET main class is given below

*Program.cs:*

using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using ikvm;


namespace QBOHibernate
{
    class Program
    {
        static void Main(string[] args)
        {

ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("antlr-2.7.7"));

ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("dom4j-1.6.1"));

ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("hibernate-commons-annotations-4.0.4.Final"));

ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("hibernate-core-4.3.5.Final"));

ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("hibernate-entitymanager-4.3.5.Final"));

ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("hibernate-jpa-2.1-api-1.0.0.Final"));

ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("hibernateqboconnect"));

ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("jandex-1.1.0.Final"));

ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("javassist-3.18.1-GA"));
            ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("
jboss-logging-3.1.3.GA"));

ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("jboss-logging-annotations-1.2.0.Beta1"));

ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("jboss-transaction-api_1.2_spec-1.0.0.Final"));

ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("mysql-connector-java-5.1.31-bin"));
            com.intuit.qbo.pbl.HibernateDriver aDrv = new
com.intuit.qbo.pbl.HibernateDriver();
            String a =
typeof(org.hibernate.cfg.Configuration).AssemblyQualifiedName;
            aDrv.*writeUser*(a);

        }
    }
}

The HibernateDriver implementation is shown below

package com.intuit.qbo.pbl;

import java.io.File;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

@SuppressWarnings("deprecation")
public class HibernateDriver {

public void *writeUser*(String hibernateFinalJarName)
 {
try {
          File f = new File("C:\\hibernateikvm\\hibernate.cfg.xml");

                 * Configuration configuration =
(org.hibernate.cfg.Configuration)Class.forName(hibernateFinalJarName).newInstance();*

  configuration.configure(f);
  ServiceRegistry sr= new
ServiceRegistryBuilder().applySettings(configuration.getProperties()).build();

  SessionFactory sf=configuration.buildSessionFactory(sr);

  User user1=new User();
  user1.setUserName("Arpit");
  user1.setUserId(1);
  user1.setUserMessage("Hello world from arpit");

  User user2=new User();
  user2.setUserName("Ankita");
  user2.setUserId(2);
  user2.setUserMessage("Hello world from ankita");
  Session ss=sf.openSession();
  ss.beginTransaction();
 //saving objects to session
  ss.save(user1);
  ss.save(user2);
  ss.getTransaction().commit();
  ss.close();
 } catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
 } catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
 } catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
 } catch(Exception e){
      //Handle errors for Class.forName
      e.printStackTrace();
 }
}

I get an error instantiating the Configuration class.

Here is more information:
*hinbernateFinalJarName = "org.hibernate.cfg.Configuration,
hibernate-core-4.3.5.Final, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null"*

I get a runtime exception when executing

* Configuration configuration =
(org.hibernate.cfg.Configuration)Class.forName(hibernateFinalJarName).newInstance();*

*An unhandled exception of type 'System.TypeInitializationException'
occurred in hibernateqboconnect.dll*
*Additional information: The type initializer for
'org.hibernate.cfg.Configuration' threw an exception.*

When I convert the jar file I get a warning

c:\hibernateikvm>ikvmc -debug -target:library hibernateqboconnect.jar
IKVM.NET Compiler version 7.2.4630.5
Copyright (C) 2002-2012 Jeroen Frijters
http://www.ikvm.net/

note IKVMC0002: Output file is "hibernateqboconnect.dll"
warning IKVMC0100: Class "javax.persistence.Id" not found
warning IKVMC0100: Class "javax.persistence.Column" not found
warning IKVMC0100: Class "javax.persistence.Entity" not found
warning IKVMC0100: Class "org.hibernate.cfg.Configuration" not found
warning IKVMC0100: Class "org.hibernate.service.ServiceRegistryBuilder" not
foun
d
warning IKVMC0100: Class
"org.hibernate.boot.registry.StandardServiceRegistry" n
ot found
warning IKVMC0100: Class "org.hibernate.service.ServiceRegistry" not found
warning IKVMC0100: Class "org.hibernate.SessionFactory" not found
warning IKVMC0100: Class "org.hibernate.Session" not found
warning IKVMC0100: Class "org.hibernate.Transaction" not found
*warning IKVMC0111: Emitted java.lang.NoClassDefFoundError in
"com.intuit.qbo.pbl*
*.HibernateDriver.writeUser(Ljava.lang.String;)V"*
*    ("org.hibernate.cfg.Configuration")*

Please let me know what I am doing wrong. Any suggestions or help is really
appreciated?

Thanks,
-Kumar.

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds

_______________________________________________
Ikvm-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ikvm-developers
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.