I liked your original idea of doing a split so I had a look around and found
that chapter 8 in the Camel in Action book had a good example.

To split the ItemDocuments what I did was this....

    public void configure() throws Exception {
        System.err.println("CONVERT STARTED");          
        from("file:src/data?noop=true")         
            .convertBodyTo(ItemDocuments.class)  
            .split().method(ItemDocumentService.class,
"splitItemsDocuments")
            .log("Split line ${body}")
            .to("jpa:org.apache.camel.example.etl.ItemEntity");         
        System.err.println("CONVERT FINISHED");     
    }

public class ItemDocumentService {
        public List<ItemDocument> splitItemsDocuments(ItemDocuments docs) {
        return docs.getItemDocumentList();
    }
}


That has worked. It has split the itemDocuments into ItemDocument objects
and I am now entering my TypeConverter code.

I have another point of confusion now though. In my type converter if only
only persist my item object the item records get inserted into the database
(success!). However, if I try to persist the promotion and sell price
documents with the item document my application starts to spit errors.

Caused by: <openjpa-2.2.1-r422266:1396819 fatal general error>
org.apache.openjpa.persistence.PersistenceException: Incorrect integer
value:
'\xAC\xED\x00\x05sr\x00,org.apache.camel.example.etl.PromotionEntity$\x0C\xF5\xF1\x08\x0B\xA2\x81\x02\x00\x05L\x00\x02idt\x00\x10'
for column 'ITEM_PROMOTION_ID' at row 1 {prepstmnt 1042322838 INSERT INTO
item (id, ATTRIBUTE_1, ATTRIBUTE_3, ATTRIBUTE_2, BRAND_LOGO_FILE_NAME,
BRAND_NAME, CLASS_NO, DEFAULT_MARGIN, DESCRIPTION, EXTENDED_DESCRIPTION,
EXTENDED_DESCRIPTION_2, GST_CODE, IMAGE_FILE_NAME, ITEM_NO,
OUT_OF_STOCK_IND, PACK_QTY, ITEM_PROMOTION_ID, ITEM_SELL_PRICE_ID,
SELLING_UNIT, SIZE_APPLICABLE, STOCK_AVAILABLE, SPPLR_NO, VOLUME,
WEB_AGE_GROUP, WEB_COLOR_DESCRIPTION, WEB_DESCRIPTION, WEB_SIZE_DESCRIPTION,
WEIGHT) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?)} [code=1366, state=HY000]
FailedObject: org.apache.camel.example.etl.ItemEntity@2d8bfa3f
        at 
org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4958)
        at
org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4918)
        at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
        at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:78)
        at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:143)
        at
org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushAndUpdate(BatchingPreparedStatementManagerImpl.java:79)
        at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:99)
        at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:87)
        at
org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:550)
        at
org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:106)
        at
org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:59)
        at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:105)
        at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:78)
        at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:735)
        at
org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131)
        ... 101 more

What I was thinking was that I could have two things wrong here.

1. In my route I have only specified
.to("jpa:org.apache.camel.example.etl.ItemEntity"); Do I need to specify the
other entities too? Or because there is a relationship between the entities
will JPA be smart enough to figure it out.

2. Perhaps I have the JPA entities set up incorrectly. In my JPA item entity
i have the relationships set up like this...

        @OneToOne(cascade = CascadeType.ALL)
        @JoinColumn(name="ITEM_PROMOTION_ID")
    private PromotionEntity promotion;
    
        @OneToOne(cascade = CascadeType.ALL)
        @JoinColumn(name="ITEM_SELL_PRICE_ID")
    private SellPriceEntity sellPrice;

I'm thinking it is the 1st one. My route is not defined properly. Do you
guys have any thoughts?

thanks



--
View this message in context: 
http://camel.465427.n5.nabble.com/How-to-write-a-type-converter-tp5741592p5741628.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to