I am a beginner to hibernate....
I have a two tables like,

t_2013
id  name
1   donald


t_2014
id   name
2    charles

This is my jpa,


  @Entity
  @Table(name="t_2013")
  public class Test implements Serializable {

@Id
@GeneratedValue
@Column(name="id")
private int id;

@Column(name="name")
private String name;

Here i create one jpa with table name of t_2013. My Question is how to get the data from t_2014 using same jpa. Is there any way to access single jpa to many tables with similar table structure

 Query
 -----
  List<Test> list=    hibernateTemplate.getSessionFactory().openSession().createSQLQuery("Select * from t_2014").list();

error:java.lang.ClassCastException:

 or

 List<Object> list=    hibernateTemplate.getSessionFactory().openSession().createSQLQuery("Select * from t_2014").list();

 if i use above code how to iterate it.

 Iterator ir=list.iterator();
 while (pairs.hasNext()) {
 Object[] pair = (Object[]) pairs.next();
 Test obj=(Test)pair[0];
 }

If i iterate above format i got this error : java.lang.Integer cannot be cast to com.model.Test. how to get data from similar table structure...

try this

List<Object[]> list=(List<Object[]>)query.list();

In order to loop through the records in the list

for(Object[] row:list) {
    Integer id=(Integer)row[0];
    String name=(String)row[1]);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.