how to make one p:datatable column be an expanded treenode - primefaces

I want to have a p:datatable which contains one column having a treenode in each cell. How should I implement this? I'm new to jsf/primefaces. Any example is really appreciated. Thanks for any help!
col1 | col2
-------------------------------------------
data1 | node1
| |--- node2
| |--- node3
| |--- node4
------------------------------------------
data2 | node5
| |--- node6
---------------------------------------------
Here is my original datatable with all String columns:
<p:dataTable id="datatable" value="#{userData.dataList}" var="data">
<p:columns value="#{userData.dataTableColumns}" var="column">
<f:facet name="header">
<h:outputText value="#{column.header}" />
</f:facet>
<h:outputText value="#{data[column.property]}" />
</p:columns>
</p:dataTable>

Related

How to disable positioning of p:overlayPanel?

I need to center my OverlayPanel in my screen.
-----------
| Button |
-----------
-------------------
| OverlayPanel |
-------------------
Here's my code:
<p:overlayPanel id="overlayPanelId" for="panelBtnId" hideEffect="fade" dynamic="true" dismissable="true">
<ui:include src="/faces/OverlayMiniSearch.xhtml"/>
</p:overlayPanel>

Caused by: java.sql.SQLException: Field 'customerNumber' doesn't have a default value - hibernate and jpa

I am working on Spring Hibernate JPA example. In this example I am simply trying to insert the record into database, but when trying to do that resulting in below. Why?
org.springframework.orm.jpa.JpaSystemException: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:310)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:221)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:417)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:131)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy39.save(Unknown Source)
at net.javabeat.springdata.CustomerTest.createCustomer(CustomerTest.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:70)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.hibernate.exception.GenericJDBCException: could not execute statement
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:189)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2987)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3499)
at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:393)
at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:227)
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:207)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:191)
at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:321)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:286)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
at org.hibernate.ejb.event.EJB3MergeEventListener.saveWithGeneratedId(EJB3MergeEventListener.java:71)
at org.hibernate.event.internal.DefaultMergeEventListener.saveTransientEntity(DefaultMergeEventListener.java:236)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:216)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:282)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:151)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:76)
at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:833)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:817)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:821)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:889)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:291)
at com.sun.proxy.$Proxy31.merge(Unknown Source)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:442)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:483)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:468)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
... 37 more
Caused by: java.sql.SQLException: Field 'customerNumber' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1901)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2113)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2049)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2034)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:186)
... 82 more
Customer.java
#Entity
#Table(name="customers")
#NamedQuery(name="Customer.findAll", query="SELECT c FROM Customer c")
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private int customerNumber;
private String addressLine1;
private String addressLine2;
private String city;
private String contactFirstName;
private String contactLastName;
private String country;
private double creditLimit;
private String customerName;
private String phone;
private String postalCode;
private String state;
//bi-directional many-to-one association to Employee
#ManyToOne
#JoinColumn(name="salesRepEmployeeNumber")
private Employee employee;
//bi-directional many-to-one association to Order
#OneToMany(mappedBy="customer",fetch = FetchType.EAGER)
private List<Order> orders;
//bi-directional many-to-one association to Payment
#OneToMany(mappedBy="customer")
private List<Payment> payments;
// setters and getters
}
Employee.java
#Entity
#Table(name="employees")
#NamedQuery(name="Employee.findAll", query="SELECT e FROM Employee e")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private int employeeNumber;
private String email;
private String extension;
private String firstName;
private String jobTitle;
private String lastName;
//bi-directional many-to-one association to Customer
#OneToMany(mappedBy="employee")
private List<Customer> customers;
//bi-directional many-to-one association to Employee
#ManyToOne
#JoinColumn(name="reportsTo")
private Employee employee;
//bi-directional many-to-one association to Employee
#OneToMany(mappedBy="employee")
private List<Employee> employees;
//bi-directional many-to-one association to Office
#ManyToOne
#JoinColumn(name="officeCode")
private Office office;
// setters and getters
}
SpringContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!-- For consider the using of annotations foe defining Spring Bean -->
<context:annotation-config />
<!-- For bootstrapping the Spring Repository -->
<jpa:repositories base-package="net.javabeat.springdata.repository" />
<!-- Load database.properties file -->
<context:property-placeholder location="classpath:database.properties" />
<!-- Enable Transaction Manager -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- Necessary to get the entity manager injected into the factory bean -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<!-- ====== MYSQL DataSource ====== -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${mysql.jdbc.driverClassName}" />
<property name="url" value="${mysql.jdbc.url}" />
<property name="username" value="${mysql.jdbc.userName}" />
<property name="password" value="${mysql.jdbc.password}" />
</bean>
<!-- ====== Hibernate JPA Vendor Adaptor ======= -->
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="${jpa.vendor.adapter.show_sql}"/>
<property name="generateDdl" value="${jpa.vendor.adapter.generateDdl}"/>
<property name="database" value="${jpa.vendor.adapter.database}"/>
</bean>
<!-- ======== Entity Manager factory ======== -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<!-- Data Source -->
<property name="dataSource" ref="dataSource"/>
<!-- JPA Vendor Adaptor -->
<property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
<!-- spring based scanning for entity classes-->
<property name="packagesToScan" value="net.javabeat.springdata.*" />
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<!-- <prop key="hibernate.enable_lazy_load_no_trans">true</prop> -->
<!-- <prop key="hibernate.cache.use_query_cache">true</prop> -->
</props>
</property>
</bean>
<!-- Transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
</beans>
CustomerTest.java
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = "classpath:SpringContext.xml")
/*#Transactional*/
public class CustomerTest {
#Autowired
private CustomerRepository customerRepository;
#Test
public void createCustomer(){
Customer customer = new Customer();
customer.setCustomerNumber(498);
customer.setCustomerName("John Kerr");
customer.setContactLastName("Kerr");
customer.setContactFirstName("John");
customer.setPhone("11.22.3333");
customer.setAddressLine1("500 Street");
customer.setAddressLine2("Green Tree Hills");
customer.setCity("London");
customer.setState("United Kingdom");
customer.setPostalCode("233214");
customer.setCountry("England");
customer.setCreditLimit(321312);
customerRepository.save(customer);
}
}
ER relationship diagram attached.
Edit-1
mysql> desc customers;
+------------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-------------+------+-----+---------+-------+
| customerNumber | int(11) | NO | PRI | NULL | |
| customerName | varchar(50) | NO | | NULL | |
| contactLastName | varchar(50) | NO | | NULL | |
| contactFirstName | varchar(50) | NO | | NULL | |
| phone | varchar(50) | NO | | NULL | |
| addressLine1 | varchar(50) | NO | | NULL | |
| addressLine2 | varchar(50) | YES | | NULL | |
| city | varchar(50) | NO | | NULL | |
| state | varchar(50) | YES | | NULL | |
| postalCode | varchar(15) | YES | | NULL | |
| country | varchar(50) | NO | | NULL | |
| salesRepEmployeeNumber | int(11) | YES | MUL | NULL | |
| creditLimit | double | YES | | NULL | |
+------------------------+-------------+------+-----+---------+-------+
mysql> desc employees;
+----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+-------+
| employeeNumber | int(11) | NO | PRI | NULL | |
| lastName | varchar(50) | NO | | NULL | |
| firstName | varchar(50) | NO | | NULL | |
| extension | varchar(10) | NO | | NULL | |
| email | varchar(100) | NO | | NULL | |
| officeCode | varchar(10) | NO | MUL | NULL | |
| reportsTo | int(11) | YES | MUL | NULL | |
| jobTitle | varchar(50) | NO | | NULL | |
+----------------+--------------+------+-----+---------+-------+
DDL would be more helpful in this case, but the message is very clear - you are trying to insert row, but the id is not being generated (even though you are using #GeneratedValue set to AUTO, see documentation).
Are you trying to map to an existing DB schema? If yes, check if the mentioned field is set to support MySQL AUTO_INCREMENT.
In your test, you are setting customer number.
Customer customer = new Customer();
customer.setCustomerNumber(498);
As you marked GeneratationType as Auto, I think you are not supposed to set customer number.

Importing multi-valued field into Solr from mySQL using Solr Data Import Handler

We have the following two tables in our mySQL:
mysql> describe comment;
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| blogpost_id | int(11) | YES | | NULL | |
| comment_text | varchar(256) | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
mysql> describe comment_tags;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| comment_id | int(11) | YES | | NULL | |
| tag | varchar(80) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
Where each comment can have multiple tags. We can import the entire comment into Solr using the Data Import Handler. However I am not sure how to import the tags for each comment into a multivalued field defined the schema.xml for each comment document.
Please advise. Thanks
You can also use GROUP_CONCAT with a Seperator(e.g " , ") and then try something like this :
<dataConfig>
<!-- dataSource is just an example. Included just for completeness. -->
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/db" user="root" password="root"/>
<document>
<entity name="comment" pk="id" query="SELECT *, group_concat(tags) as comment_tags FROM comment" transformer="RegexTransformer">
<field column="blogpost_id" name="blogpost_id"/>
<field column="comment_text" name="comment_text" />
<field column="tag" name="comment_tags" splitBy = "," />
</entity>
</document>
</dataConfig>
It'll increase the Performance and also will remove the Dependency of another query.
Try something like this:
<dataConfig>
<!-- dataSource is just an example. Included just for completeness. -->
<dataSource batchSize="500" type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/my-database" user="root" password="somethinglong1283"/>
<document>
<entity name="comment" pk="id" query="SELECT * FROM comment">
<field column="blogpost_id" name="blogpost_id"/>
<field column="comment_text" name="comment_text" />
<entity name="comment_tags" pk="comment_id" query="SELECT * FROM comment_tags WHERE comment_id='${comment.id}'">
<field column="tag" name="tag" />
</entity>
</entity>
</document>
If other solution not work then try this one.
<dataConfig>
<!-- dataSource is just an example. Included just for completeness. -->
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/db" user="root" password="root"/>
<document>
<entity name="comment" pk="id" query="SELECT *, group_concat(tags) as tag FROM comment" transformer="RegexTransformer">
<field column="blogpost_id" name="blogpost_id"/>
<field column="comment_text" name="comment_text" />
<field column="tag" splitBy="," sourceColName="tag"/>
</entity>
</document>
</dataConfig>
Add field in schema.xml
<field name="tag" type="string" indexed="true" stored="true" multiValued="true"/>
If you want to use custom separator in mysql then use below one.
GROUP_CONCAT(tags SEPARATOR '~,~') AS tags
If you want to DISTINCT in concat tag then
GROUP_CONCAT(DISTINCT tags SEPARATOR '~,~') AS tags

Mapping items with multiple rows from mysql to solr

So I have a normalized table with some data that I want to put into a Solr index, something akin to this
+----+--------------+--------------+---------+
| id | name | attribute | value |
+----+--------------+--------------+---------+
| 1 | Apple | color | green |
| 1 | Apple | shape | round |
| 1 | Apple | origin | Belgium |
| 2 | Motorbike | type | fast |
| 2 | Motorbike | nr of wheels | 2 |
| 3 | Office chair | color | grayish |
| 3 | Office chair | spins | yes |
+----+--------------+--------------+---------+
Now, I would prefer to have it to be indexed as one document per unique id (i.e. item). But then I will have to consolidate n attributes into a single document. To do this I would need to do some magic with my dataConfig. But how can I store and map n fields? Is this the right time to use dynamic fields?
Here is my current try. I'm pretty sure it's not valid.
<dataConfig>
<dataSource
type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/mystuff"
user="root" password="*****"/>
<document name="doc">
<entity name="t1" query="select * from item_to_id_table">
<field name="id" column="id"/>
<field name="name" column="name"/>
<entity name="t2" query="select * from my_flat_table"
cacheKey="t1.id"
cacheLookup="t2.id">
<!-- alt 1 -->
<field name="$(t2.attribute)" column="value" />
<!-- alt 2 -->
<entity name="properties" query="select property, value from t2"
cacheKey="$(t2.attribute)"
cacheLookup="property">
<field name="$(properties.property)" column="value" />
</entity>
</entity>
</entity>
</document>
</dataConfig>
I'm pretty sure neither of the two alternatives are valid, I'll try them out soon unless I can figure out something better. Perhaps a script transform as a third alternative.
Is this use case reasonable to use with Solr?
I solved this the way described here.
In short I used a script transform to turn the 'properties' entity rows into fields with a prefix, "p_". Somewhat like this (example code, there may be bugs):
<dataConfig>
<dataSource
type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/mystuff"
user="root" password="*****"/>
<script>
<![CDATA[
function formProperty(row) {
var propName = row.get("property");
var propVal = row.get("value");
var fieldName = "p_" + propName;
row.put(fieldName,propVal);
return row;
}
]]>
</script>
<document name="doc">
<entity name="t1" query="select * from item_to_id_table">
<field name="id" column="id"/>
<field name="name" column="name"/>
<entity name="t2"
query="select * from my_flat_table
where my_flat_table.id = ${t1.id}"
transformer="script:formProperty">
</entity>
</entity>
</document>
</dataConfig>
I then mapped them into the solr schemata in schema.xml as dynamic fields
<dynamicField name="p_*" indexed="true" stored="true" type="string"/>

Flex DataGrid in GridItemRenderer

I've got some hierarchical data that I would like to show in a Flex Spark DataGrid, looking something like this:
|------|---------------------------|
| row1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| in | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| outer|---------------------------|
| grid | a component that spans |
| | over multiple columns here|
|----------------------------------|
| row2 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| in | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| outer|---------------------------|
| grid | a component that spans |
| | over multiple columns here|
|----------------------------------|
What I'm trying to do is to use a custom GridItemRenderer that holds an inner DataGrid. The basic concept looks something like this:
<s:DataGrid dataProvider="{outerDataProvider}" width="100%" height="100%" variableRowHeight="true">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="name">
<s:itemRenderer>
<fx:Component>
<s:DefaultGridItemRenderer />
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
<s:GridColumn>
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<s:states>
<s:State name="normal" />
<s:State name="toggled" />
</s:states>
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:HGroup>
<s:DataGrid dataProvider="{data.innerDataProvider}" columns="{outerDocument.myDynamicGeneratedColumns}">
</s:DataGrid>
<s:Group>
<s:ToggleButton label="Toggle" />
</s:Group>
</s:HGroup>
<MyComponent width="100%" height="50" includeIn="toggled" />
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>
I'm experiencing some serious performance issues when adding the inner DataGrid. Vertical scrolling is horribly slow.
I've been trying to understand what to optimize, but I'm not really sure where to begin. The inner DataGrid need to have a dynamic number of columns, and I guess this is one of the parts where something needs to be done.
Is it completely wrong to do something like this? Could I use another component than DataGrid for the inner Grid structure and get better performance?
The grid is basicly a grid containing images depending on the values inside each row.
Any suggestions or links to DataGrid tips?
How about using a list with a TileLayout for the inner grid. This would definitely perform much better:
<s:List>
<s:layout>
<s:TileLayout/>
</s:layout>
</s:List>