anil kumar

Ranch Hand
+ Follow
since Feb 23, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by anil kumar

Hi

I am new to Hibernate.I tried onetomany relation ship between Person and Address classes.
My person.hbm.xml file

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="onetomanynew">
<class name="Person">
<id name="personId">
<generator class="native"/>
</id>
<property name="personName"/>
<set name="address" cascade="all" >
<key column="ParentpersonId"/>
<one-to-many class="Address" />
</set>
</class>
</hibernate-mapping>

address.hbm.xml is a simple one for persisting the data.

And my client class is

public static void main(String[] args) throws Exception
{
Address a1=new Address();
a1.setAddress("VSP");
Address a2=new Address();
a2.setAddress("VSP1...");
Person p=new Person();
p.setPersonName("Anil ");
Set s=new HashSet();
s.add(a1);
s.add(a2);
p.setAddress(s);
Session session=HibernateUtil.getSessionFactory().openSession();
Transaction t=session.beginTransaction();
session.save(a1);---------1
session.save(a2);---------2
session.save(p);

t.commit();
session.close();

}

If i comment the lines 1 and 2 i am getting error

Exception in thread "main" net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 0, of class: onetomanynew.Address.

If i don't comment those lines it is persisting well.

I want to do lik this.

If i persist Person Class then Adress class should also persist.

How to do that ?

And why am i getting that error ?

Please explain that.


Regards

Anil Kumar
Hi

This is the error i got when i tried to run the client

java.lang.ClassCastException: com.sun.xml.internal.messaging.saaj.soap.ver1_1.Me
ssage1_1Impl cannot be cast to com.sun.xml.messaging.saaj.soap.MessageImpl
at com.sun.xml.rpc.client.StubBase._postSendingHook(StubBase.java:231)
at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:324
)
at webservices.NwordServiceIF_Stub.getNumberString(NwordServiceIF_Stub.j
ava:70)
at client.NwordServiceClient.main(NwordServiceClient.java:15)


I have deployed the webservice in the sun server 8.2 and JDK 5.0.And the service is running.

I know basics of webservices and i am trying to learn.I am using JAX-RPC.

Could any one tell me,what to do to resolve this error.




Thanks & Regards

Anil Kumar
Hi

I am new to Hibernate and i am trying to learn.I am trying for one-to-many mapping and i am getting this net.sf.hibernate.NonUniqueObjectException exception.


This is my User.java


public class User {
private int userId;
private String userName;
private Set phone;;
/** Creates a new instance of User */
public User() {
}

public int getUserId() {
return userId;
}

public void setUserId(int userId) {
this.userId = userId;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public Set getPhone() {
return phone;
}

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

}

And this is Phone.java


public class Phone {
private int phoneId;
private long number;

/** Creates a new instance of Phone */
public Phone() {
}

public int getPhoneId() {
return phoneId;
}

public void setPhoneId(int phoneId) {
this.phoneId = phoneId;
}

public long getNumber() {
return number;
}

public void setNumber(long number) {
this.number = number;
}



}

User.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 package="newonetomany">
<class name="User">
<id name="userId">
<generator class="native"/>

</id>

<set name="phone" cascade="all" >
<key column="fklUserId"/>
<one-to-many class="Phone"/>


</set>
<property name="userName"/>
</class>

</hibernate-mapping>


Main.java

try
{
Session session=HibernateUtil.getSessionFactory().openSession();
Transaction t=session.beginTransaction();
User u1=new User();
u1.setUserName("kumar");

Phone p=new Phone();
p.setNumber(1);


Phone p1=new Phone();
p1.setNumber(2);


Set s=new HashSet();
s.add(p);
s.add(p1);
//session.save(p);
//session.save(p1);

u1.setPhone(s);

session.save(u1);

session.flush();
t.commit();
session.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}



If i persist Phone object seperately ,it is working fine.But if i do with out persisting the phone object.It is throwing the above exception.Please see the commented line of code i.e session.save(p) .


Why i am getting that exception ??

Thanks

Anil Kumar
Hi

Ben

Thanks i got it.


Thanks

Anil Kumar
16 years ago
Hi

HttpServletRequest,HttpServletResponse both are interfaces.So the methods which are present in these two interfaces will be implemented by the container vendor.But where is he giving that implementation?? means on which class is he giving that implementation?



Thanks

Anil Kumar
16 years ago
Hi Peer

Thank you ,I have got it




Thanks & Regards

Anil Kumar
16 years ago
Hi

Peer i have understood,but i have one more doubt.

xmlns:mh="http://www.Monson-Haefel.com/jwsbook"

in the above why do we have to use xmlns:mh??
can't we say mh="http://www.Monson-Haefel.com/jwsbook" ???


Please clarify this.

Thanks

Anil Kumar
16 years ago
<schema xmlns="http://www.w3.org/2001/XMLSchema"

xmlns:mh="http://www.Monson-Haefel.com/jwsbook"
targetNamespace="http://www.Monson-Haefel.com/jwsbook">


I have understood the url specified in the xmlns and also the url specified in the targetNamespace,but i am not able to understand the
attribute xmlns:mh.

Can any body explain me what does it mean???


Thanks

Anil Kumar
[ March 14, 2008: Message edited by: anil kumar ]
16 years ago
Hi

If any thread enters into a synchronized block.Then that thread is having the lock on that object.If any thread wants to enter into that synchronized block,they have to wait untill the thread holding the lock completes it's execution(Means leaving the lock)

Thanks

Anil Kumar



SCJP 5.0,SCWCD 1.4
Hi

Can any tell me where is Eratta for Head First EJB 2.0 book?

Thanks

Anil Kumar
Hi

Congrats...



Thanks

Anil Kumar
17 years ago
Hi

This is the exact question.Now let me know.

Which of the following statements are true?

Choose at least one answer.
a. HttpServletResponseWrapper takes a constructor parameter of type HttpServletResponse Correct
b. Filters are called in the order they appear in the deployment descriptor Correct
c. Methods of the wrapper classes must not be overridden Incorrect
d. Filters are an example of the Intercepting Filter design patttern Correct
e. Filters can only be invoked on incoming requests, and not on a dispatcher forward or include



The answers are a,b,d.


I think option b is wrong.



Thanks

Anil Kumar
Hi

So, the statement is false.

Am i right??


Thanks for the clarification


Thanks

Anil Kumar
Hi


Is this statement right???

Filters are called in the order they appear in the deployment descriptor

i think this statement is false.Because depending up on request ,the container will check the DD and then it will find the url patterns and <servet-name> tags.If both are there then it will first go with <url-pattern> tag and then <servlet-name> tag.


AM i right???

source Marcus Green Mock Exams


Thanks

Anil Kumar
Congrats Chandra...

All the best...



Regards

Anil Kumar
17 years ago