anil gowda

Greenhorn
+ Follow
since Jun 12, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by anil gowda


Only rows are getting deleted whenever i deploy or redeploy the application.

Does i need to change my persistence.xml file. if so what should i add more ?? can you please help me out.

Thank you.
Hi Friends,

I'm trying a sample app in which i'm using EJB3 ,JPA and Hibernate.


In this application i'm trying to persist a pojo(entity bean) into database and i'm able to do that.

But the problem is when i undeploy or redeploy the application the data in Database is getting deleted don't know how!!

Here's complete code:

persistence.xml
------------------
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">

<persistence-unit name="EJB3P1PU" transaction-type="RESOURCE_LOCAL">
<non-jta-data-source>java:/MySqlDS</non-jta-data-source>
<class>com.kalki.entity.Customer</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>

</persistence>

-------------------------------------------

Hello.java--->StatelessSessionBean

@Remote(HelloRemote.class)
@Stateless
@TransactionManagement(value=TransactionManagementType.BEAN)
public class Hello implements Serializable, HelloRemote {
@PersistenceUnit(unitName="EJB3P1PU")
private EntityManagerFactory factory;
//EntityManager em;
EntityTransaction et;
Query q;
@Resource
private EJBContext context;
protected Customer cust;

public void insert(String name,int phone)
{

EntityManager entityManager = factory.createEntityManager();
EntityTransaction entityTransaction = entityManager.getTransaction();
entityTransaction.begin();
System.out.println("--------inside hello bean------");
cust=new Customer(name,phone);
entityManager.persist(cust);
entityTransaction.commit();
entityManager.close();
}

}

----------------------------------------------------------
Customer.java---->Entity Bean


@Entity
@Table(name="customer")
public class Customer implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String name;
private int phone;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getPhone() {
return phone;
}

public void setPhone(int phone) {
this.phone = phone;
}

public Customer() {
}
public Customer(String name, int phone)
{

this.name=name;
this.phone=phone;
}

public Integer getId() {
return this.id;
}

public void setId(Integer id) {
this.id = id;
}

public int hashCode() {
return (this.id == null) ? 0 : this.id.hashCode();
}

public boolean equals(Object object) {
if (object instanceof Customer) {
final Customer obj = (Customer) object;
return (this.id != null) ? this.id.equals(obj.id)
: (obj.id == null);
}
return false;
}

}

-------------------------------------

HelloRemote.java ---->Remote Interface

import javax.ejb.Remote;

@Remote
public interface HelloRemote {

public void insert(String name,int phone);
}



------------------------------------
Client.java ----> Client class

public class Client {
public static void main(String[] args) {


try {
InitialContext ctx = new InitialContext();
HelloRemote bean=(HelloRemote)ctx.lookup("Hello/remote");
bean.insert("anil",996985);
System.out.println("inserted-------------");

} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}


--------------------------------------

Help me out if i'm wrong or i missed to configure something which is required.


Thanks in advance,
Anil.

Its working fine now. Error was because of a jar file i missed to add in classpath.

Thank you,
Anil
Thanks a lot jaikiran its working now.

One more doubt..Can i use hibernate with ejb3(without JPA)??
Hi Friends,

I'm developing a project where i need to use EJB3 with jdk 6. I'm using jboss-5.0.1.GA, but it does not support jdk6.

I tried to deploy a EJB3 app which is using jdk6 in jboss-5.0.1.GA but i could not succed. when i tried the same using jdk5 it worked

So if any of you have an idea regarding this please help me.

I need to know which version of jboss supports jdk6.

Thanks in advance,
Anil.
Hi jaikiran,

I am using Myeclipse IDE, im deploying the app in jboss-5.0.1.GA and i have added jbossall-client.jar to the build path.
As i said in my previous post that the app is getting deployed but when i run the client program im getting the exception.

Am i missing to add any other jar files?? Can you please list out the jars i should add to build path.

Thanks in advance,
Anil

Hello All!

I'm trying to develop a sample application using EJB3.

application has been deployed successfully...no problem with that.

But, when i try to call bean from my client code im getting following exception.


Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.kalki.session.MyBeanRemote
at com.kalki.session.MyBeanclient.main(MyBeanclient.java:28)


Here's is my complete code.

Super interface--->IMyBean

package com.kalki.session;

import java.io.Serializable;

public interface IMyBean extends Serializable{

public void show();


}

---------------------------------
Remote Interface----->>MyBeanRemote

package com.kalki.session;

import javax.ejb.Remote;

@Remote
public interface MyBeanRemote extends IMyBean{

}

---------------------------------------
Local Interface--->MyBeanLocal

package com.kalki.session;

import javax.ejb.Local;

@Local
public interface MyBeanLocal extends IMyBean{

}

--------------------------------------------
Session Bean---MyBean

package com.kalki.session;

import javax.ejb.Stateless;

@Stateless
public class MyBean implements MyBeanLocal, MyBeanRemote {



public void show()
{
System.out.println("Hi how are you");
}


}

----------------------------------------------
Client Class---->MyBeanclient

package com.kalki.session;

import java.util.Hashtable;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class MyBeanclient {

/**
* @param args
*/
public static void main(String[] args) {
try {




Properties properties = new Properties();
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs","=org.jboss.naming:org.jnp.interfaces");
properties.put("java.naming.provider.url","localhost:1099");
Context context;

context = new InitialContext(properties);
MyBeanRemote bean = (MyBeanRemote)context .lookup("MyBean/remote");
bean.show();

} catch (NamingException e) {
e.printStackTrace();
}

}

}

I googled for solution but it is of no help.

Please help me.

Thanks in advance,
Anil
Hi all,

Thanks for your replies, Actually i just gave a scenario i,e storing user id and password in session ...im not going to store the password in session by any means, i'm storing the userid which will be helpful in identifying the particular user among many.

regards,
anil
16 years ago
Hi all,

Can anyone tell me how can i store information in a session.?

suppose if i want to store Login detail that is USERID and PASSWORD in
a session how can i do it?


Thanks in advance,
Anil
16 years ago
I'm using Servlets in my application and HTML page for User registration and i have taken following info for registration.
1)first name
2)last name
3)login name
4)password
5)email id

I have created the table for storing these info..and i have created the login page also but i want to know how can i store the user info in the session after they logs in and how can make them send msgs to each other

kindly help,
anil
16 years ago
Hi friends,

Im new to J2EE and i need help from you all as i'm developing an application where i should be able to following things kindly help me.

My application
---------------
1)Users have to register first.
2)After loging in they must have an option to send and receive messages from each other. i,e they should have a message box where all the messages gets stored.

Please guide me out, i doesnot knw how can i implement this.


thanks in advance,
Anil
16 years ago