Nilesh Yawale

Greenhorn
+ Follow
since Dec 16, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Nilesh Yawale

Employee.java



Machine.java



EmployeeManager.java



Employee.hbm.xml



Machine.hbm.xml



hibernate.cfg.xml

Any Update....please.

Thanks for your time.

Nilesh Yawale
Hi Mark,

Thanks for the reply. But if you see my Employee.hbm.xml file there is a property metioned as -

<one-to-one name="macId" column= "MAC_ID" class= "emp.Machine" />

Please let me know your comments on the same.

Thanks for your time.

Nilesh
Hi All,

I'm using Hibernate 3.1.1 and MySQL 5.0.

Following is my first hibernate program for one-to-one mapping as follows -

Employee.java
package emp;

public class Employee {
private Long empId;

private String ename;
private String city;
private int salary;

public Employee() {
}
/****************************************************/
public Long getEmpId() {
return empId;
}

public void setEmpId(Long empId) {
this.empId = empId;
}
/****************************************************/
public String getEname() {
return ename;
}

public void setEname(String ename) {
this.ename = ename;
}

/****************************************************/

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

/****************************************************/
public int getSalary() {
return salary;
}

public void setSalary(int salary) {
this.salary = salary;
}
/****************************************************/
Machine machine=new Machine();

public Machine getMachine() {
return machine;
}

public void setMachine(Machine machine) {
this.machine = machine;
}

}

Machine.java

package emp;

import java.util.*;
public class Machine {

private String macId;
private String ipAddr;
//private String empId;

public Machine () {
System.out.println("in cons of mac");
}

Set empId= new HashSet();
/****************************************************/
public String getMacId() {
return macId;
}

public void setMacId(String macId) {
this.macId = macId;
}

/****************************************************/
public String getIpAddr() {
return ipAddr;
}

public void setIpAddr(String ipAddr) {
this.ipAddr = ipAddr;
}

}

EmployeeManager.java

package emp;
import org.hibernate.*;
import java.util.*;

import util.HibernateUtil;

public class EmployeeManager {
static Employee empObj=null;
static Machine mac = null;
/******************************************************/
public static void main(String[] args) {
EmployeeManager mgr = new EmployeeManager();

if (args[0].equals("storeMac")) {
mgr.createAndStoreMac(args[1],args[2]);
System.out.println("mac data stored...");
}
else if (args[0].equals("storeEmp")) {
String macid=mgr.createAndStoreMac(args[1],args[2]);
mgr.createAndStoreEmp(args[3],args[4],Integer.parseInt(args[5]),macid);
}
/******************************************************/
private Long createAndStoreEmp(String name, String city, int salary, String macId)
{
System.out.println("in emp...");
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();

empObj= new Employee();

empObj.setEname(name);
empObj.setCity(city);
empObj.setSalary(salary);

Machine macObj = (Machine) session.load(Machine.class, macId);

empObj.setMachine(macObj);
session.save(empObj);
System.out.println("session id in create..........."+session);

session.getTransaction().commit();
System.out.println("in emp tx commited...");
return empObj.getEmpId();
}

/*************************************************************/
private String createAndStoreMac(String macId, String ipAddr)
{
System.out.println("in store mac...");
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();

Machine mac= new Machine();

mac.setMacId(macId);
mac.setIpAddr(ipAddr);
session.save(mac);

session.getTransaction().commit();
System.out.println("in dept... tx done");
return mac.getMacId();
}
}

Employee.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="emp.Employee" table="myEmployee">

<id name="empId" column="EMP_ID">
<generator class="native"/>
</id>

<property name="name" column="NAME" type="string"/>
<property name="city" column="EMP_City"/>
<property name="salary"/>
<one-to-one name="macId" column= "MAC_ID" class= "emp.Machine" />

</class>

</hibernate-mapping>

Machine.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="emp.Machine" table="myMachine">

<id name="macId" column="MAC_ID"/>

<property name="ipAddr" column="IP_ADDR" type="string"/>

</class>

</hibernate-mapping>

hibernate.cfg.xml

<?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>

<!-- Database connection settings -->
<property name="connection.url">jdbc:mysql://localhost/Hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

<mapping resource="emp/Employee.hbm.xml"/>
<mapping resource="emp/Machine.hbm.xml"/>

</session-factory>

</hibernate-configuration>


When I tried to run the above code I'm getting following exception -

in store mac...
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Initial SessionFactory creation failed.org.hibernate.MappingException: Could not read mappings from resource: emp/Employee.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at util.HibernateUtil.<clinit>(HibernateUtil.java:17)
at emp.EmployeeManager.createAndStoreMac(EmployeeManager.java:110)
at emp.EmployeeManager.main(EmployeeManager.java:19)
Caused by: org.hibernate.MappingException: Could not read mappings from resource: emp/Employee.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:484)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1453)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1421)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1402)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1378)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1298)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1284)
at util.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 2 more
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:424)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:481)
... 9 more
Caused by: org.xml.sax.SAXParseException: Attribute "column" must be declared for element type "one-to-one".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:421)
... 10 more


Please let me know what might be the reason behind it.

Thanks for your time.

Nilesh
Hello All,

I'm using SunOne 8 on Windows XP and trying to use the following code to lookup. Also I've verified the deployment of my application on the server.

Context initial = new InitialContext();
Object objref = initial.lookup("java:comp/env/ejb/test");

and appserv-rt.jar and j2ee.jar are in my classpath.

I'm getting javax.naming.NameNotFoundException: No object bound for java:comp/env/ejb/test exception.

Please let me know if anybody knows the probable reason or solution for the above issue.

Thanks for your time

Nilesh
19 years ago
Hello All,

I went through the documenation available regarding deployment of JCA on JBoss. But I didn't find the information regarding how to deploy Non JDBC XA resource adapter. Is there anybody knows how to perform this deployment or is there any information available for the same on the internet?

Please give your suggestion as it'll be really helpful for me.

Nilesh
19 years ago
Hi All,

I'm using Weblogic application server 7.0.4 for my application. All my transactions are container managed. Also I'm not using multithreading. But I'm getting many deadlocks. My connection pool size is 100.

Can anybody suggest me the probable reasons of it and solutions?

Thanks in advance

Nilesh
20 years ago
Hi All,
Can I use Statement object for multiple queries in different threads?..kindly explain.

Thanks in advance for your support.
Hi All,
I'm trying to use two resource adapters of type local transaction in single transaction. I first started the user transaction then trying to get the connection of two different EIS. But I'm getting errors
java.lang.IllegalStateException: Local transaction already has 1 non-XA Resource: cannot add more resources.
at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.enlistResource(J2EETransactionManagerOpt.java:99)
at com.sun.enterprise.resource.ResourceManagerImpl.registerResource(ResourceManagerImpl.java:97)
at com.sun.enterprise.resource.ResourceManagerImpl.enlistResource(ResourceManagerImpl.java:71)
at com.sun.enterprise.resource.PoolManagerImpl.getResource(PoolManagerImpl.java:142)
at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:200)
at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:140)
at myjca.MyDataSource.getConnection(MyDataSource.java:41)
at com.softwareag.solution.spw.jca.ejb.ConnectorBean.getOracleConnection(Unknown Source)
at com.softwareag.solution.spw.jca.ejb.ConnectorBean.addRoleToProjectWebAndSmartApps(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.sun.enterprise.security.SecurityUtil$1.run(SecurityUtil.java:72)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.enterprise.security.application.EJBSecurityManager.doAsPrivileged(EJBSecurityManager.java:968)
at com.sun.enterprise.security.SecurityUtil.runMethod(SecurityUtil.java:76)
at com.softwareag.solution.spw.jca.ejb.ConnectorBean_EJBObjectImpl.addRoleToProjectWebAndSmartApps(ConnectorBean_EJBObjectImpl.java:121)
at com.softwareag.solution.spw.jca.ejb._ConnectorBean_EJBObjectImpl_Tie._invoke(Unknown Source)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:648)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:191)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1655)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1514)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:896)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:172)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:668)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.dispatch(SocketOrChannelConnectionImpl.java:352)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.read(SocketOrChannelConnectionImpl.java:261)
at com.sun.corba.ee.impl.transport.ReaderThreadImpl.doWork(ReaderThreadImpl.java:73)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:382)

Can anybody clarify it?
Thanks in advance..
Hi All,
I'm trying J2EE connector architecture on J2EE 1.4 Application server. Is it possible to register resource adapter as webservice? Also I'm using a session bean to use the resource adapter. How to register EJBs as webservice on J2EE 1.4 application server?
Thanks in advance for your support.
20 years ago
Hi All,
Can anybody tell what is the role of architect in IT. No theory please. Just share your experiences and observation....
Thanks for your time.