Page 1 of 1
Retrieve datas from 2 tables using DataSourceFactory -SOLVED
Posted: Wed Dec 05, 2012 12:00 pm
by denis
Hi,
I would like to retrieve all groups (Business and Consumer) and display them into a listGrid, but i have a problem.
I have :
- Super class CustomerGroup (annoted with @MappedSuperclass so i don't have any table into the database)
- BusinessGroup extends CustomerGroup
- ConsumerGroup extends CustomerGroup
I am able to display all BusinessGroup or ConsumerGroup but i have not found how to retrieve both.
My GroupListDataSourceFactory :
Code: Select all
public void createDataSource(String name, OperationTypes operationTypes, Object[] additionalItems, AsyncCallback<DataSource> cb) {
if (dataSource == null) {
operationTypes = new OperationTypes(OperationType.BASIC, OperationType.BASIC, OperationType.BASIC, OperationType.BASIC, OperationType.BASIC);
PersistencePerspective persistencePerspective = new PersistencePerspective(operationTypes, new String[]{}, new ForeignKey[]{});
DataSourceModule[] modules = new DataSourceModule[]{
//Here BusinessGroup
new BasicClientEntityModule("my.company.profile.domain.BusinessGroup", persistencePerspective, AppServices.DYNAMIC_ENTITY)
};
dataSource = new ListGridDataSource(name, persistencePerspective, AppServices.DYNAMIC_ENTITY, modules);
dataSource.buildFields(null, false, cb);
} else {
if (cb != null) {
cb.onSuccess(dataSource);
}
}
}
if i add a new BasicClientEntityModule for ConsumerGroup :
Code: Select all
DataSourceModule[] modules = new DataSourceModule[]{
//Here BusinessGroup
new BasicClientEntityModule("my.company.profile.domain.BusinessGroup", persistencePerspective, AppServices.DYNAMIC_ENTITY),
//Here ConsumerGroup
new BasicClientEntityModule("my.company.profile.domain.ConsumerGroup", persistencePerspective, AppServices.DYNAMIC_ENTITY)
};
it doesn't work.
Or if I use the super class :
Code: Select all
DataSourceModule[] modules = new DataSourceModule[]{
new BasicClientEntityModule("my.company.profile.domain.CustomerGroup", persistencePerspective, AppServices.DYNAMIC_ENTITY)
};
error :
Code: Select all
[ WARN] BaseHibernateCriteriaDao - rowCount projection for the given criteria did not result a single integer value, returning zero - did you add unnecessary paging constraints to the criteria?
Can you help me please?
Re: Retrieve datas from 2 tables using DataSourceFactory
Posted: Fri Dec 07, 2012 12:28 pm
by jefffischer
I think your ceiling entity is too specific. Try changing it to an interface that both groups implement, or a higher level class they both derive from. For example:
Code: Select all
new BasicClientEntityModule("my.company.profile.domain.CustomerGroup", persistencePerspective, AppServices.DYNAMIC_ENTITY)
Re: Retrieve datas from 2 tables using DataSourceFactory
Posted: Fri Dec 07, 2012 1:49 pm
by denis
denis wrote:Or if I use the super class :
Code: Select all
DataSourceModule[] modules = new DataSourceModule[]{
new BasicClientEntityModule("my.company.profile.domain.CustomerGroup", persistencePerspective, AppServices.DYNAMIC_ENTITY)
};
error :
Code: Select all
[ WARN] BaseHibernateCriteriaDao - rowCount projection for the given criteria did not result a single integer value, returning zero - did you add unnecessary paging constraints to the criteria?
Can you help me please?
Hi Jeff,
Thanks for your answer but it's what i have tried and it doesn't work, there is an error when i use the super class :
Code: Select all
[ WARN] BaseHibernateCriteriaDao - rowCount projection for the given criteria did not result a single integer value, returning zero - did you add unnecessary paging constraints to the criteria?

Re: Retrieve datas from 2 tables using DataSourceFactory
Posted: Mon Dec 10, 2012 8:22 am
by denis
Do you have another idea?
Re: Retrieve datas from 2 tables using DataSourceFactory
Posted: Wed Dec 12, 2012 12:59 pm
by jefffischer
Hmm, that's odd - may be a bug in Broadleaf related to @MappedSuperclass usage. Two other things I would try:
1) Try not using @MappedSuperclass, and instead make CustomerGroup a true entity and have your more specific types derive from that. Then, use CustomerGroup in your admin datasource definition.
OR
2) Make BusinessGroup and ConsumerGroup implement a common interface. Then, use the interface name in your admin datasource definition.
Re: Retrieve datas from 2 tables using DataSourceFactory
Posted: Wed Dec 12, 2012 1:07 pm
by denis
Ok i will try it tomorrow !
Thanks!
Re: Retrieve datas from 2 tables using DataSourceFactory
Posted: Thu Dec 13, 2012 9:26 am
by denis
Hi,
Unfortunately both solutions don't work :-/.
That's odd because i tried to just add a String in consumerGroup and businessGroup but :
- I see all fields in the right column (normal case)
- when i click on add button only ConsumerGroup and CustomerGroup are displayed, never BusinessGroup.

SuperClasss CustomerGroup :
Code: Select all
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "MY_CUSTOMER_GROUP")
@AdminPresentationClass(friendlyName = "CustomerGroup", ceilingDisplayEntity = "my.company.core.profile.domain.CustomerGroup")
public class CustomerGroup implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "GroupId")
@GenericGenerator(name = "GroupId", strategy = "org.broadleafcommerce.common.persistence.IdOverrideTableGenerator", parameters = {
@Parameter(name = "increment_size", value = "1"),
@Parameter(name = "segment_value", value = "CustomerGroup"),
@Parameter(name = "entity_name", value = "my.company.core.profile.domain.CustomerGroup") })
@Column(name = "GROUP_ID")
@AdminPresentation(friendlyName = "CustomerGroup_ID", group = "CustomerGroup_Primary_Key", visibility = VisibilityEnum.HIDDEN_ALL)
protected Long id;
@Column(name = "GROUP_NAME")
@AdminPresentation(friendlyName = "CustomerGroup_Name", prominent = true)
protected String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Class BusinessGroup :
Code: Select all
@Entity
@Table(name = "MY_BUSINESS_GROUP")
@AdminPresentationClass(friendlyName = "BusinessGroup")
public class BusinessGroup extends CustomerGroup {
private static final long serialVersionUID = 1L;
@Column(name = "GROUP_TEST_BUSINESS")
@AdminPresentation
private String testBusinessGroup;
public String getTestBusinessGroup() {
return testBusinessGroup;
}
public void setTestBusinessGroup(String testBusinessGroup) {
this.testBusinessGroup= testBusinessGroup;
}
}
ConsumerGroup :
Code: Select all
@Entity
@Table(name = "MY_CONSUMER_GROUP")
@AdminPresentationClass(friendlyName = "ConsumerGroup")
public class ConsumerGroup extends CustomerGroup {
private static final long serialVersionUID = 1L;
@Column(name = "GROUP_TEST_CONSUMER")
@AdminPresentation
private String testConsumerGroup;
public String getTestConsumerGroup() {
return testConsumerGroup;
}
public void setTestConsumerGroup(String testConsumerGroup) {
this.testConsumerGroup= testConsumerGroup;
}
}
DatasourceFactory :
Code: Select all
public class GroupListDataSourceFactory implements DataSourceFactory {
public static ListGridDataSource dataSource = null;
public void createDataSource(String name, OperationTypes operationTypes, Object[] additionalItems, AsyncCallback<DataSource> cb) {
if (dataSource == null) {
operationTypes = new OperationTypes(OperationType.BASIC, OperationType.BASIC, OperationType.BASIC, OperationType.BASIC, OperationType.BASIC);
PersistencePerspective persistencePerspective = new PersistencePerspective(operationTypes, new String[]{}, new ForeignKey[]{});
DataSourceModule[] modules = new DataSourceModule[]{
new BasicClientEntityModule("my.company.core.profile.domain.CustomerGroup", persistencePerspective, AppServices.DYNAMIC_ENTITY)
};
dataSource = new ListGridDataSource(name, persistencePerspective, AppServices.DYNAMIC_ENTITY, modules);
dataSource.buildFields(null, false, cb);
} else {
if (cb != null) {
cb.onSuccess(dataSource);
}
}
}
Maybe a bug in BLC 2.1.0-SNAPSHOT
Re: Retrieve datas from 2 tables using DataSourceFactory
Posted: Thu Dec 13, 2012 10:59 am
by denis
If it's not possible for now, i can use a single table customerGroup with a groupType (Consumer or Business), but in that case, i have a problem when i add a customer (business or consumer) i would like display only business group or consumer group but all groups are displayed because MyCustomer contains :
Code: Select all
@ManyToOne(targetEntity = CustomerGroup.class)
@JoinColumn(name = "GROUP_ID", nullable = false)
@AdminPresentation(friendlyName = "MyCustomer_Group", group="CustomerImpl_Customer")
@AdminPresentationToOneLookup
private CustomerGroup group;

Is it possible to filter the datasource to retrieve only groups corresponding at the customer type? Because i tried everything by following this thread :
http://forum.broadleafcommerce.org/viewtopic.php?f=13&t=528&p=1602&hilit=be+this+hard#p1602 but in my case when i click on add button i have no possibility to retrieve the selected entity type to add and filter on...
Please help we are stuck in all cases :-/
Re: Retrieve datas from 2 tables using DataSourceFactory
Posted: Fri Dec 14, 2012 1:34 pm
by jefffischer
This looks like it was a bug in the framework. This problem does not happen when the ceiling entity used in the datasource is an interface (which is the case with all BLC entities). Since your ceiling entity pointed to a concrete implementation rather than an interface, the bug was exposed.
This issue is addressed in
http://jira.broadleafcommerce.org/browse/BLC-799.
I also just generated a snapshot release that contains this fix. You'll need to change your dependency version to 2.1.1-SNAPSHOT.
Re: Retrieve datas from 2 tables using DataSourceFactory
Posted: Fri Dec 14, 2012 2:45 pm
by denis
Thanks Jeff i will try it ASAP !
Edit : Everything is Ok now ! Thanks again