Anna Madhusudhanan

Greenhorn
+ Follow
since Jan 03, 2006
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 Anna Madhusudhanan

Hi, Waht you are telling is correct.
To retrive the Employee object , if i use Session object it is working fine. if i use EntityManager , it is not working.

// ERROR GIVING CODE...
javax.persistence.EntityManager manager = getManager(); //JNDI LOOKUP

EMployee emp = manager.find(Employee.class, new Long(empNo));
//i got the emp object

String name = emp.getName(); // This returns me Employee name.

//if i try this line i am getting error.

int departmentNo = emp.getDepartment().getDepartmentNo();

In the above line i am getting the
"org.hibernate.LazyInitializationException: could not initialize proxy - no Session", session is closed.


//WORKING CODE

javax.persistence.EntityManager manager = getManager(); //JNDI LOOKUP

EntityManagerImpl entityImpl =
(EntityManagerImpl) entityManager.getDelegate();

org.hibernate.Session session = entityManagerImpl.getSession();

Employee emp = session.get(Employee.class, new Long(empNo));

String name = emp.getName();

int deptNo = emp.getDepartment().getDepartmentNo();

session.close();

These lines are working fine.

In the first model, i am getting the error.

I am using Jersey(RESTFUL WEBSERVICES), GlassFish server, Hibernate.

Am i missing any confiuration. Or anything?

As per assumption is, When we call entitymanager.find method, the entitymanager opens a session and create the employee object, close the session and then return the employee object.

So at the time of calling the emp.getDepartment().getDepartmentNo() method,The code tries to get the department object, but the session is closed, so we are getting this error.
If my assumption is correct, my question is how can i get the department object from the Employee object?

Please help me.

Thanks
Anna
[ July 22, 2008: Message edited by: Anna Madhusudhanan ]
Hi
I am getting the "org.hibernate.LazyInitializationException: could not initialize proxy - no Session" error while running my application:
I am using the Restful Webservices in GlassFish application server. I configured the Hibernate properties in the persistence.xml file. (GlassFish App server + Hibernate + Restful Webservices(jersey)).
I am using the Lazy loading.

Assume these is the situation:

I have Employee object and Department object.

The department object is declared as the member variable in the Employee object.

Public class Employee {

public int empno;
public String empName;
public Department department;

public void setDepartment(Department dept){
//......
//......
//do something
}

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "XYZ")
public Department getDepartment(){
//......
//......
//do something
}



//setter and getting for each methods
}

public class Department {
//......
//......
}


i am getting this Employee object using EntityManger find method .
I got the employee object and if i exeucte the getEmpNo oir getEmpName , i am getting the value.

but if i try to get the Department(while running the getDepartment method),
I am getting this

"org.hibernate.LazyInitializationException: could not initialize proxy - no Session"

Please could you explaing me , where is the problem and which one causing the problem.
15 years ago
Hi
I am getting the "org.hibernate.LazyInitializationException: could not initialize proxy - no Session" error while running my application:
I am using the Restful Webservices in GlassFish application server. I configured the Hibernate properties in the persistence.xml file. (GlassFish App server + Hibernate + Restful Webservices(jersey)).
I am using the Lazy loading.

Assume these is the situation:

I have Employee object and Department object.

The department object is declared as the member variable in the Employee object.

Public class Employee {

public int empno;
public String empName;
public Department department;

public void setDepartment(Department dept){
//......
//......
//do something
}

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "XYZ")
public Department getDepartment(){
//......
//......
//do something
}



//setter and getting for each methods
}

public class Department {
//......
//......
}


i am getting this Employee object using EntityManger find method .
I got the employee object and if i exeucte the getEmpNo oir getEmpName , i am getting the value.

but if i try to get the Department(while running the getDepartment method),
I am getting this

"org.hibernate.LazyInitializationException: could not initialize proxy - no Session"

Please could you explaing me , where is the problem and which one causing the problem.
Hi
I am getting the "org.hibernate.LazyInitializationException: could not initialize proxy - no Session" error while running my application:
I am using the Restful Webservices in GlassFish application server. I configured the Hibernate properties in the persistence.xml file. (GlassFish App server + Hibernate + Restful Webservices(jersey)).
I am using the Lazy loading.

Assume these is the situation:

I have Employee object and Department object.

The department object is declared as the member variable in the Employee object.

Public class Employee {

public int empno;
public String empName;
public Department department;

public void setDepartment(Department dept){
//......
//......
//do something
}

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "XYZ")
public Department getDepartment(){
//......
//......
//do something
}



//setter and getting for each methods
}

public class Department {
//......
//......
}


i am getting this Employee object using EntityManger find method .
I got the employee object and if i exeucte the getEmpNo oir getEmpName , i am getting the value.

but if i try to get the Department(while running the getDepartment method),
I am getting this

"org.hibernate.LazyInitializationException: could not initialize proxy - no Session"

Please could you explaing me , where is the problem and which one causing the problem.
Hi,
In my applcation Some of the users belongs to manager1 and some of the users belongs manager2.

The following is the existing code.

if (request.isUserInRole("manager1")) {
//do the process1
}

Now i want to change the code to do the process1 for manager2 also.

so i need to add the following condition in my code:

if (request.isUserInRole("manager2")) {
//do the process1
}

it works fine. But i don't want to change my code frequenlty. Becuase tomorrows i need to add the for managerXYZ for the same process.

so i changed in my servlet code as:

if (request.isUserInRole("MANAGER")) {
//do the process1
}

in the web.xml i changed as follows:

<security-role-ref>
<role-name>MANGAER</role-name>
<role-link>manager1</role-link>
</security-role-ref>

<security-role-ref>
<role-name>MANAGER</role-name>
<role-link>manager2</role-link>
</security-role-ref>

but it is not working as expected way. only manager2 users is successful, not for manager1. I think the manager2 is override the manager1.
How can i make multiple role links pointed to a single role_name.

Please help me.

Thanks
Anna Madhusudhanan
16 years ago
Hi,
I created signed jar file(applet), the jnlp file and a html file(html file calls the jnlp file, hypelink). I put these file into the deploy folder. When i click the link the jar files has been downloaded in to the local system, but the web start does not open the applet.

Please help me.

Thanks in advance.

Thanks and regards
Anna Madhusudhanan
17 years ago
Hi
I am opening a PDF file using servlet output stream.
It opens a separate application in the acrobat. But the file name is randamly gnerated. i don't know why it gives random names (like AcrCD.tmp).

My code

res.setHeader("Content-length",fileLength);
res.setHeader("Content-type","application/pdf");
res.setHeader("Content-disposition","inline; filename=" + fileName );

res.setContentType("application/pdf");
res.setContentLength((int)file.length());
OutputStream outstream = res.getOutputStream();
while((len=inputstream.read(buffer))>0)
{
outstream.write(buffer,0,len);
}
inputstream.close();
outstream.flush();
outstream.close();

It is not opening with the filename.pdf, it opens with acr01.tmp.
Can any one help regarding this one.

Thanks in advance
Anna
18 years ago