Patrick Tsang

Greenhorn
+ Follow
since Aug 31, 2004
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 Patrick Tsang

Yeah, I asked the same question in Hibernate forum, but
it looks there is nobody gave a solution. Here is the link

http://forum.hibernate.org/viewtopic.php?t=962069

My current workd-around is to delete the existing data manually,
it'd kind of dumb, but at least it works.

//NOTE: Delete the exisiting students
Query q = session.createQuery("DELETE FROM Student
WHERE teacherid = :teacherId");
q.setInteger("teacherId",teacherId);
q.executeUpdate();
if you are not using JTA stuff, you need to call transaction.commit()
This is the exact problem I met, if you have it solved,
it's appreciated to keep me updated.

BTW, I read the manual, and add "all,delete-orphan" on the
parent's hbm.xml,but it doesn't work
My goal: everytime when I update the teacher, I will reassign the students to this teacher, for example, Case A: Teacher 1 have student 1,2,3, now I want to assign 4 to this teacher, but remove 1,2,3. Case B: Teacher 1 have student 1,2,3, now I want to assign 1,4,5 to this teacher

My question is, Do I need to run the query (marked in the //NOTE below),or hibernate itself will figure that out?I tried that a couple times, it seems I have to do the deletion manually, or I just doing something wrong?

Hibernate version:
3.1.3

Mapping documents:
Domain objects:
DomainTeacher.java
DomainStudent.java


DB objects:
Teacher.java
private int teacherid;
private String teachername;
private Set students;
//getter and setter
-----------------------------------
teacher.hbm.xml
<class name="Teacher" table="Teacher">
<id name="teacerid" column="TeacherID" type="java.lang.Integer">
<generator class="identity" />
</id>

<property name="teachername" column="teachername" type="java.lang.String"/>
<set name="students" inverse = "true" cascade = "all">
<key column="TeacherID" /> <one-to-many class="Student"/>
</set>


Student.java
private Teacher teacher;
private studentname;
//getter and setter

public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Student)) return false;
final Student stu = (Student) o;
if (!this.teacher.equals(stu.getTeacher()) return false;
if (!studentname.equals(stu.getStudentname)) return false;
return true;
}

public int hashCode() {
int result;
result = this.teacher.hashCode();
result = 29 * result + this.studentname.hashCode();
return result;
}

----------------------------------------
student.hbm.xml
<class name="Student" table="Student">
<composite-id>
<key-many-to-one name="Teacher" class="Teacher" column="TeacherID"/>
<key-property name="studentname" column="studentname" type="java.lang.Integer"/>
</composite-id>


Code between sessionFactory.openSession() and session.close():
TeacherDAO:

public void updateTeacher(DomainTeacher domainTeacher ){
int teacherId = domainTeacher.getTeacherid();
Teacher teacher = (Teacher)session.get(Teacher.class, teacherid)
teacher.setTeachername(domainTeacher.getTeachername);

//NOTE: Delete the exisiting students
Query q = session.createQuery("DELETE FROM Student
WHERE teacherid = :teacherId");
q.setInteger("teacherId",teacherId);
q.executeUpdate();

Set<Student> students = new HashSet<Student>();
Set<DomainStudent> domainStudents = domainTeacher.getDomainStudents();
for(DomainStudent ds: domainStudents){
Student student = new Student();
student.setTeacher(teacher);
student.setStudentname(ds.getStudentname());
students.add(student);
}

teacher.setStudents(students);
session.save(teacher);
}
I implemented the NTLoginModule via JAAS at tomcat, the information I require for authentication is username biding with domain,and password. For instance, on the logon.jsp page, the user will input
User name: "myDomain\myUsername"
Password: "myPassword"

In my cases, I meet 3 scenarios as following:

1)Logon with correct domain,username,password, PASSED
2)Logon with wrong domain, correct username, password, FAILED,
but if I logon again with correct domain,username,password, FAILED
3)Other combination, FAILED,but if logon again with the correct
credentials, PASSED.

I check all log files,and can't figure out why #2 is happen, that is,
once I logoned with a wrong domain and correct username/password,
it will fail on the subsequent logon trials.

Anybody meet the similar scenario before? Any hints are
highly appreciated.

Patrick
19 years ago
Just retrieve whatever data you wanna display in the jsp page(Imagine you will show it in textarea, but, save it in a hidden object this time). When the mouse moveover event is executed, call the javascript to pass the hidden value as the tips. Just my 2 cents.
19 years ago
JSP
In my project, the current implementation is to generate the navigation tree on server-side with the JAVA/XML/XSLT. Is that a better solotion?I heard of JAXB, but not sure whether it owns a competative edge on this.

On the client-side expand/collapse, it seems javascript is the only reasonalbe solution? Correct me if I am wrong.
19 years ago
JSP
All datas that will displayed in the tree are stored in database, and it's required to refresh the navigation tree, and all branchs can be colapsed/expanded.

I searched some solution, but most of them are in javascript and binding
with the static/fixed data in the tree.

Any hints?
19 years ago
JSP
This forum doesn't allow the scripting, I have to change the <> to **
By default, the IE status bar will shows the HyperLink if you move the mouse over a Link, also, it will shows the executing status like
"Opening [url=http://www.javaranch.com/index.jsp".]http://www.javaranch.com/index.jsp".[/url]

I am trying to read this message into my variable,
AGAIN, I need to READ it from the system status bar, but not
WRITE to the bar as the simple -- window.status="my own message"

My test code:
---------------------------------------------------------------
*html*
*s c r i p t language="j a v a s c r i p t"*
function howStatusBarMsg(){
var message=window.status;
alert(message);
}
*/s c r i p t*
*body*
*a href="http://www.javaranch.com/index.jsp" on M ouseOver="showStatusBarMsg()"*Link*/a*
*/body*
*/html*
---------------------------------------------------------------
But it doesn't work, any hints?

Why do a dumb thing like this? because there is something happen very weird on my page, I need to track where it goes,step by step
Sorry for that, I have made the change.
19 years ago
JSP
I met a problem which has the same scenario with the one
on http://www.orionsupport.com/1053715234630.resource
(Env: WinXP + J2SE 1.4 + Tomcat 4.1)

"The problem I have found is that if you have security enabled (via security-constraint, login-config, security-role etc in web.xml), and have a short session timeout, any user activity after the timeout expires causes a redirect back to the auth-method (e.g FORM).Once authentication is successful, processing then continues where the user left off however any context objects that were bound to the previous session are lost and the results are unpredictable. I too would like to detect the timeout and redirect to a "proper" login however the presence of security is causing me a problem. Does anybody where I can tap into the logic flow or if there is a class or method that I can extend to do it my way?"

Any input is appreciated.
19 years ago
JSP