One Star

Delimited file to Java business model & Hibernate

Hello,
I'm new user with Talend Open Studio. My goal is to read several "tab" delimited files and to write in several MySql tables, that don't have the same structure.
But I'm having a quite complex Java Business Model, with several MySql tables mapped through Hibernate.
I wonder if I could use Hibernate and my Java Business Model inside TOS in order to make mapping easier.
In that case, I wouldn't have to handle sequential generated index that make link between tables.
Here is an example of what I think about :
- Input file format :
oldId ; name ; road ; city
- Output MySql tables :
table PERSON : idPerson (automatically generated) ; name
table ADRESS : idAdress (automatically generated) ; fk_idPerson (link to PERSON.id) ; road ; city
What I would like to do is to import my business Java classes and to write some code inside TOS like this :
Person p = new Person();
Adress a = new Adress();
p.setName(input.name);
a.setRoad(input.road);
a.setCity(input.city);
p.setAdress(a);
myPersonDao.save(p);
Is there a way to do something like this ?
If not, what would be the best way to do that ? More particularly, how can I make reference in Adress table to the generated Person index ?
Thanks for any help.
5 REPLIES
Employee

Re: Delimited file to Java business model & Hibernate

Hello,
You can add your own library and your own Java classes through the Code/Routine repository items.
Regards,
One Star

Re: Delimited file to Java business model & Hibernate

Thanks for your quick reply !
Do you think using my Hibernate DAO library would be a good way to do that ? Or is there a better way ?
Does people sometimes do like this ?
I ask for this question, because I searched in forum for "hibernate" keyword, but nobody seems to talk about that... So I'm wondering if it may cause problems...
Looking at TOS components, I suppose I will have to use tJavaRow or tJavaFlex, with nothing in output, but only Java code that call my DAO... I'll try that
One Star

Re: Delimited file to Java business model & Hibernate

About automatically generated index and foreign-key (working with tMysqlOutput), I found the answer here : http://www.talendforge.org/forum/viewtopic.php?pid=5509#p5509
About using Java business model and Hibernate, I got it working. However, it is very very slow !!
Are there recommandations to work like this with good performances ? Or is it just non adapted to insert massive data ?
Thanks
Employee

Re: Delimited file to Java business model & Hibernate

Hibernate is a great library, but I would be really surprised if you get good performance results with such a library.
I can only advice (if not already done) to avoid connection to the db in the main / row part of your generated code (this is why tJavaFlex seems to be adapted to your problem)
HTH,
One Star

Re: Delimited file to Java business model & Hibernate

Indeed, at first time, I had put DB connection in "main" part ! :/
When I corrected it, it was 3 or 4 times faster... but not really performant...
I think I will stay on tMysqlOutput...
Thanks for your help and advices !