I have a object which contains an ArrayList with "Group" objects. Every Group object have a ArrayList of "Table" objects and these objects have a ArrayList with "Field" objects. All these object have their own properties as well like "name" etc.
I want to render this object in jasper reports but I'm having trouble figuring out how to iterate and group by Group's name and Table name and then iterate through the fields..
Not really sure how I should pass the object to the report and how I should handle it.
The result in my report should look something like this.
GroupA
GroupA information
Table A object name and version
Field1, properties...
Field2, properties...
Table B Object name and version
Field1, properties...
Field2, properties...
Group B
...
You can pass your data to the report by wrapping it in a JRBeanCollectionDataSource. That would iterate groups in the report detail band.
To further iterate on sublists, you can use lists, tables or subreports (also passing the sublists by wrapping them in JRBeanCollectionDataSource).
Related
I want to join two table:
T1:id,name,email
T2:id,address
to join I am doing this:
String hql="select sd.name,tt.name from T1 sd,T2 tt where sd.id=tt.id";
Query q=ss.createQuery(hql);
List l2=q.list();
Object o1=l2.get(0);
System.out.println("-----------");
System.out.println(o1.toString());
System.out.println("-----------");
It is returning object but dont get how to retrieve the values as returned object is not entity object.
Every result is an Object Array.The Array's size is the select columns
List l2=q.list();
Object[] o1=(Object[])l2.get(0);//The size is should be 2
System.out.println(o1[0]);
System.out.println(o1[1]);
You have to cast the Object's in the List to your specific type, Hibernate does not know the type. See What is the "proper" way to cast Hibernate Query.list() to List<Type>? and Hibernate query for selecting multiple values
it will return array of Object which you need to typecast as per your select values like name etc.
List<Object[]> values= (List<Object[]>)q.list();
for(Object[] val: values){
....
//your specific type values
}
Another option is creating a view with your joined tables, then, create hibernate entity base on that view
I am working on a requirement. Currently there is a search page which has List Box with Values (Example Data) 1) Employee and 2) Sport Person.
Object Hierarchy (Hibernate Bean)
Person is the actual Object which has two different class
1) Employee and
2) Sports Person based
Discriminator Column
Person_Type (Discriminator Column).
On a search page , if user selects any of the list box, will result the data from that sub class.
Now requirement is to show both sub class result together and it is done by adding one more value in the list box as "Employee + Sports Person".
Problem's
1) Both sub class have different structure
2) There are other criteria which are compared with different attributes.
How can I union the two sub classes.
Please help me to resolve.
Please Note : I am trying not use Query Based Union. I am think in terms of OOPS
Loading both types of persons should not be a problem. If your query can access common attributes you can do FROM Person p WHERE <whatever_person_criteria_you_have>.
If your query need to use specific attributes of Employee and SportsPerson then you could execute 2 queries and put the result into a single List<Person>.
Sorting/displaying that list depends on what data needs to be displayed or compared. In case you have to compare different data, you could always use a Comparator<Person> which checks the actual class of the objects and maybe a wrapper which does the same to access the correct properties for display.
I use hql to query from database. first query returns a list of objects like this
see image:
as you can see, the field names of retrieved objects are obvious (ID, TIMESTAMP, ...)
but in the second query, what I get, is this:
see image:
and I need to change field names ([0] to ID , 1 to TITLE, ...)
any solutions?!
Create a simple data holding object that contains your needed data.
Fill your data into such an object
Add this object to a new list/array
View the debugger on this list again
Using an object that extends HibernateDaoSupport, I ran a query using this right here:
List<Object> trialList2 = getSession().createSQLQuery(trialQuery2).list();
Where trialQuery2 is just some query that returned a single row. I got back a list with one Object on it, which when inspected in Eclipse looks like this:
[some, random, data]
I'd like to create an Object that can accommodate what I got back from the query, but a simple Javabean object that can has those fields doesn't seem to work. Does anyone know what kind of object I would have to make to be able to access those values?
It would be actually Object[] not Object
List<Object[]> trialList2
Based on columns in your select query, you get values from index
Let us say, if your query is select firstname, lastname from employee;
Object[0] would be firstname
Object[1] would be lastname.
As per documentation :
These will return a List of Object arrays (Object[]) with scalar values for each column in the table
U can replace any class name for BEANCLASSNAME
List<BEANCLASSNAME> trialList2 = getSession().createSQLQuery(trialQuery2).setResultTransformer(new AliasToBeanResultTransformer(BEANCLASSNAME.class)).list();
I'm doing some weird reporting from a JPA data store.
I need to select (using EJBQL) a list of objects. These objects contain collection of entities. I have a class that is constructed by:
FOOBean(String param1,
String param2,
List<Entity> listParam)
(notice that third parameter is a list)
And I want to select a list of these beans using GROUP BY, fetching listParam along, so I would like to write a query that works like this:
SELECT new FOOBean(
e1.param1,
e1.param2,
e1)
FROM Entity e1
GROUP BY e1.param1, e1.param2
So that grouped entities are fetched into a list and inserted into the third parameter. Is it possible to do it that way or do I have to create two queries that selects distinct pairs of param1 and param2; and fetches all entities with appropriate param values respectively?
It is not possible, at least in JPA 1.0 (and I doubt that in JPA 2.0 it is different).
I think it would be much better to retrieve the object based on your condition & then use #oneToMany annotaion in your entity to set up the list.