Charu Sama

Greenhorn
+ Follow
since Aug 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 Charu Sama

I wanted to know whether Struts 2 works well with jdk1.4?
14 years ago
Do we really need DAO layer if working with Hibernate, JPA or any other mapping framework. I had long discussion on this topic .....

Some says yes, but I donot know why??? just for HIbernateTemplate.save() or EntityManager.persist(), ?

Is this not a good design decision to omit DAO layer and let the Frameork do their jobs like generating SQL behind the secene, resource management.
It worked. I just played with <cascade><cascade-all/></cascade> in school.xml. When I p�t cascade code I was getting this error
Caused by: java.sql.BatchUpdateException: ORA-00957: Doppelter Spaltenname

Then I removed and worked
private int school_student_FK;
I have problem persisting parent - child (School-Students) object. I am using EJB3 JPA, Hibernate EnityManager. I am not using annotation but trying to do with separate mapping file.

Below code only inserts school record but students donot get inserted. And, there is no error on the console.

userTransaction.begin();
em.persist(school);// **school is saved but should persist student as well**
userTransaction.commit();

Below is my object model and logic. I have doubt on mapping on school.xml and student.xml where I ahve defined association.


SCHOOL Table
===============
school_idPK
school_name

STUDENTS Table
=================
student_idpk
student_name
school_student_FK : reference school_id of School table


School.java
-----------------
private int school_id;
private String school_name;
private List total_students_list

Followed by setter and getter



Students.java
-------------------
private int student_id;
private String student_name;
private int school_student_FK;

Followed by setter and getter



school.xml
---------------

<entity class="School" name="School">
<table name="SCHOOL"/>

<attributes>
// manual entered id
<id name="school_id">
<column name="school_id"/>
</id>
<basic name="school_name">
<column name="school_name" />
</basic>

<one-to-many name="total_students_list" fetch="EAGER" mapped-by="school" target-entity="Students">

</one-to-many>

</attributes>
</entity>



student.xml

<entity class="Students" name="Students">
<table name="Students"/>

<attributes>
// manual entered id
<id name="student_id">
<column name="student_id"/>
</id>
<basic name="student_name">
<column name="student_name" />
</basic>

<many-to-one name="school" target-entity="School" >
<join-column name="school_student_FK" referenced-column-name="school_id"/>
</many-to-one>
</attributes>
</entity>



Client code written in EJB
----------------------------


@TransactionManagement(TransactionManagementType.BEAN)
public class MyEJB
{
@PersistenceContext(unitName = "school")
EntityManager em;

@Resource

public UserTransaction userTransaction;

School school = new School();
school.setchool_id(100);
school.setschoolName("My School");

Student student= new Student();
student.setStudent_Id(10);
student.setStudentName("MyName");

Student student1= new Student();
student.setStudent_Id(20);
student.setStudentName("MyName");

List<Students> studentsList = new ArrayList<Students>();
studentsList.add(student);
studentsList.add(student1);
school.total_students_list(studentsList);

userTransaction.begin();
em.persist(school);// ** shcool is save but should save student as well**
userTransaction.commit();

}

I am trying to delete multiple files from the directory using the below code but it does not work.

String filelocation = "C:\\test\\*.txt";
File myFile= new File(filelocation);
myFile.delete();

But, below code works, when I give exact file name. but, i this case only file is deleted.
String filelocation = "C:\\test\\hello.txt";
File myFile= new File(filelocation);
myFile.delete();

How do I delete multiple files in one shot?
16 years ago
Can we connect to multiple resources/db in a single transaction (using connection object) using plain JDBC. No JTA and no Container?
Yes, but even CMP/JPA also need this if I am correct.
But, this is specific to Hibernet.
One simple question - Why compositePK class needs to implement Serializale interface?
Please share your thoughts on this.

Thanks in advance.
I was looking into simple many-to-many mapping for two entities user and group, which involved 3 tables i.e. table USER, table GROUP and table USER_GROUP. so, my question is - do we really need table USER_GROUP for this mapping. Is there other way to do the many-to-many mapping just with 2 tables USER and GROUP (without USER_GROUP).
What is the significance of having USER_GROUP table?

Please provide your input.

Thanks in advance.
I am working on a Hibernate Project and some of my database tables does not have Primary Key. I looked into Hibernate reference and could found how to handle a table which does not have PK on it. So, I am wondering if Hibernate supports table mapping without PK ???
Has anyone come across this situation ???