I recently upgraded BeanIO in my project from 1.2.3 to 2.0.6 and as part of that upgrade I had to modify some of my mappings that where using the Bean element to start using Segment element.
But what I noticed is that previously if a line in a stream had to little fields beanio would still initialize the object defined in the bean element in the mapping. Where as now in the same scenario the property that should be set with the object is simply set to null.
Old code that worked and populated the testName property with a empty Test object:
<bean name="testName" class="com.project.Test">
<field name="test1" type="string" default=""/>
<field name="test2" type="string" default=""/>
</bean>
New code that doesn't initialize the Test object and sets the testName property to null:
<segment name="testName" class="com.project.Test" minOccurs="0">
<field name="test1" type="string" default="" minOccurs="0"/>
<field name="test2" type="string" default="" minOccurs="0"/>
</segment>
Is there a way to force the Segment element to always initialize an object?
(Yes I do need to keep minOccurs="0" and no if I remove it, it doesn't solve the issue)
Thx,
goe
Try setting org.beanio.createMissingBeans=true in a beanio.properties file at the root of your classpath.
Related
I am new to Hibernate. I am trying to map both my super-class and sub-class to a single table.
<class name="Employee" table="EmpWithManager">
<id name="id" column="ID">
<generator class="native"></generator>
</id>
<discriminator column="EMP_TYPE" type="string"></discriminator>
<property name="firstName" column="FIRST_NAME"></property>
<property name="lastName" column="LAST_NAME"></property>
<property name="salary" column="SALARY"></property>
<subclass name="Manager" extends="Employee">
<property name="managerId" column="MAN_ID"></property>
<property name="noOfEmployees" column="NUMBER_EMP"></property>
</subclass>
</class>
This works fine but if change the position of the discriminator tag as follows:
<class name="Employee" table="EmpWithManager">
<id name="id" column="ID">
<generator class="native"></generator>
</id>
<property name="firstName" column="FIRST_NAME"></property>
<discriminator column="EMP_TYPE" type="string"></discriminator>
<property name="lastName" column="LAST_NAME"></property>
<property name="salary" column="SALARY"></property>
<subclass name="Manager" extends="Employee">
<property name="managerId" column="MAN_ID"></property>
<property name="noOfEmployees" column="NUMBER_EMP"></property>
</subclass>
</class>
This re-ordering gives me the below exception:
Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)".
Please anybody tell me why this is happening and whether the position of discriminator should be in the beginning?
If you look at the http://hibernate.org/dtd/ entry for hibernate-mapping-3.0.dtd it defines the class element as follows. Order is important as this is a DTD. Note that discriminator? comes after (id|composite-id) and before the long entry with property. This ordering requirement is not explicitly mentioned in the (current) hibernate documentation.
<!ELEMENT class (
meta*,
subselect?,
cache?,
synchronize*,
comment?,
tuplizer*,
(id|composite-id),
discriminator?,
natural-id?,
(version|timestamp)?,
(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,
((join*,subclass*)|joined-subclass*|union-subclass*),
loader?,sql-insert?,sql-update?,sql-delete?,
filter*,
fetch-profile*,
resultset*,
(query|sql-query)*
)>
According to the hibernate document type definitions (DTD) listed here, the position of the discriminator tag must be after the id tag. Essentially the structure of the xml document in this situation is pre-defined, and you must follow the pre-defined format, and that is why you see an error after moving the discriminator tag.
From the JBoss docs:
5.1.8 - Discriminator:
The <discriminator> element is required for polymorphic persistence using the table-per-class-hierarchy mapping strategy and declares a discriminator column of the table. The discriminator column contains marker values that tell the persistence layer what subclass to instantiate for a particular row. A restricted set of types may be used: string, character, integer, byte, short, boolean, yes_no, true_false.
I'd imagine that you must define how properties will be discriminated against before you define them and that is the reasoning for the structure within the DTD.
Good Day Community,
I have a question regarding castor unmarshaling in java. As mentioned I am using castor to unmarshal a webservice response that contains a byte array (byte[])
.. please refer to below:
public class ViewReportResponse {
private String reportId;
private byte[] report;
//getters and setters here ...
I have used castor before to unmarhsal webservice responses, but admittedly, the responses previously where always strings. The problem lyes with the byte array returned as I believe castor chokes on unmarshaling it.
My castor-mapping file is provided below:
<class name="com.domain.reporting.client.service.ViewReportResponse">
<map-to xml="viewReportResponse"
xsi:schemaLocation="http://domain.com/schemas/reportingService/generateReport"
ns-uri="http://domain.com/schemas/reportingService/generateReport"
ns-prefix="ns2" />
<field name="reportId">
<bind-xml name="reportId"
node="element"
type="string"/>
</field>
<field name="report">
<bind-xml name="report"
node="element"
type="bytes" />
</field>
I'm not sure what I am missing, but the message is received but fails at the point of unmarshaling.
I've attached a clip of the error below.
org.springframework.oxm.UnmarshallingFailureException: Castor unmarshalling exception; nested exception is org.exolab.castor.xml.MarshalException: unable to find FieldDescriptor for 'report' in ClassDescriptor of viewReportResponse.
Please any assistance is much appreciated.
Thank-you kindly
Solved:
The general problem is not the maping to and from the byte[]. The problem is related to the use of namespace in this case.
<field name="reportId">
<bind-xml name="ns:reportId" xmlns:ns="http://domain.com/schemas/reportingService/generateReport"
node="element"
type="string"/>
<field name="report">
<bind-xml name="ns:report" xmlns:ns="http://domain.com/schemas/reportingService/generateReport"
node="element"
type="bytes"/>
This post is now effectively solved and closed.
I am trying to perform search result aggregation (count and sum) grouping by several fields in a nested fashion.
For example, with the schema shown at the end of this post, I'd like to be able to get the sum of "size" grouped by "category" and sub-grouped further by "subcategory" and get something like this:
<category name="X">
<subcategory name="X_A">
<size sum="..." />
</subcategory>
<subcategory name="X_B">
<size sum="..." />
</subcategory>
</category>
....
I've been looking primarily at Solr's Stats component which, as far as I can see, doesn't allow nested aggregation.
I'd appreciate it if anyone knows of some way to implement this, with or without the Stats component.
Here is a cut-down version of the target schema:
<types>
<fieldType name="string" class="solr.StrField" />
<fieldType name="text" class="solr.TextField">
<analyzer><tokenizer class="solr.StandardTokenizerFactory" /></analyzer>
</fieldType>
<fieldType name="date" class="solr.DateField" />
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
</types>
<fields>
<field name="id" type="string" indexed="true" stored="true" />
<field name="category" type="text" indexed="true" stored="true" />
<field name="subcategory" type="text" indexed="true" stored="true" />
<field name="pdate" type="date" indexed="true" stored="true" />
<field name="size" type="int" indexed="true" stored="true" />
</fields>
The new faceting module in Solr 5.1 can do this, it was added in https://issues.apache.org/jira/browse/SOLR-7214
Here is how you would add sum(size) to every facet bucket, and sort descending by that statistic.
json.facet={
categories:{terms:{
field:category,
sort:"total_size desc", // this will sort the facet buckets by your stat
facet:{
total_size:"sum(size)" // this calculates the stat per bucket
}
}}
}
And this is how you would add in the subfacet on subcategory:
json.facet={
categories:{terms:{
field:category,
sort:"total_size desc",
facet:{
total_size:"sum(size)",
subcat:{terms:{ // this will facet on the subcategory field for each bucket
field:subcategory,
facet:{
sz:"sum(size)" // this calculates the sum per sub-cat bucket
}}
}
}}
}
So the above will give you the sum(size) at both the category and subcategory levels. Documentation for the new facet module is currently at http://yonik.com/json-facet-api/
There is a patch SOLR-3583, which adds percentiles and averages to facets, pivot facets, and distributed pivot facets by making use of range facet internals. It is possible to add sums to pivot facets by improving this patch.
For example, averages can be calculated for categories using this url:
http://localhost:8983/solr/select?q=*%3A*
&facet=true
&facet.pivot=category,subcategory
&facet.stats.percentiles=true
&facet.stats.percentiles.averages=true
&facet.stats.percentiles.field=size
&f.size.stats.percentiles.requested=25,50,75
&f.size.stats.percentiles.lower.fence=0
&f.size.stats.percentiles.upper.fence=1000
&f.size.stats.percentiles.gap=10
See also this video and slides for more details.
1. Counts
To get the counts, you can use Pivot Faceting. It will generate a list very similar to what you asked but with counts only.
You'll need to append this to your query:
&facet=true&facet.pivot=category,subcategory
Note that this works on Solr 4.0 and after.
2. Sums
As for the sums, I think you can achieve them with ordinary facets but using a facet query instead of facet field.. I'm not entirely sure of this one, I'll try it out and re-post if found anything useful.
I am trying to use an external objects in my report.
I added the jar file with external objects to iReport classpath (in settings)
The static text (with I18n)
msg($R{pdf.invoice.finalTitle}, $P{invoice.number})
I have added such definitions into xml:
<import value="crm.object.objects.Invoice"/>
<parameter name="invoice" class="crm.object.objects.Invoice" isForPrompting="false">
<property name="number" value=""/>
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
...
But still it fails during compilation with error: net.sf.jasperreports.engine.design.JRValidationException: Report design not valid : 1. Parameter not found : invoice.number
What I am doing wrong?
Thank you
The parameter you have defined is "invoice", not "invoice.number". So, it should be $P{invoice}. You can then access it's variable, if it has enough access privileges...or by it's getter, as $P{invoice}.getNumber()
I am trying the Data Import Handler for MySQL Database.
I added the DIhandler in solrconfig.xml, created a data-config.xml according to my database scheme and also added a field in the schema.xml which was different. I am connecting with MySQL database
After i connect and I run the dataimport?command=full-import i get this response
"00C:\solr\conf\data-config.xmlfull-importidle1102011-03-05 15:01:04Indexing completed. Added/Updated: 0 documents. Deleted 0 documents.2011-03-05 15:01:042011-03-05 15:01:040:0:0.400This response format is experimental. It is likely to change in the future."
The xml files are in this http://pastebin.com/iKebKGSZ
<field column="manu" name="manu" />
<field column="id" name="id" />
<field column="weight" name="weight" />
<field column="price" name="price" />
<field column="popularity" name="popularity" />
<field column="instock" name="inStock" />
<field column="includes" name="includes" />
Are these fields also in your schema.xml?
I couldnt see them in the pastebin link. Make sure you have all fields in your schema as well.