views:

36

answers:

3

We have a simple data model reflecting the following...

  1. User contains many @OneToMany addresses
  2. User contains many @OneToMany phones
  3. User contains many @OneToMany emails
  4. User belongs to a @Organization via @ManyToOne

We would like the customers to capture all user information in a excel / csv sheet and provide it to our upload tool. We provide a simple user interface to capture the order of fields for the import. We didn't face any issues when we supported imports for just User (i.e. we let the end user define the order of imported fields and used the same in the excel)

We are not sure what would be the right strategy to support @OneToMany and @ManyToOne fields. The problems are as follows.

  1. Not sure how to flatten the information if a User has multiple addresses into a flat line (e.g. User1 has 2 addresses, 1 phone, 3 emails and User 2 has 1 address, 1 phone ...)
  2. How to handle @ManyToOne annotations (you can't expect the end user to provide a primary key - Integer id in this case), do you expect them to provide a Organization name here assuming post import the user can modify this information if necessary
  3. How to handle delta values during an import operation (say 10 additional users?)
  4. Do you have a single import file for Organization, Users, UserAdress and all the dependent objects?

Are there any tools / APIs which abstract some of these needs for both importing / exporting?

+1  A: 

You can flatten the structure like you would do in a database i.e. read a table for users, a table for addresses and so on.

You could read the csv or excel to an in-memory-db and use hibernate to build business objects for you.

tkr
how would you address the foreign key relationship(s) (e.g. address has a reference to the user id, will you use something like loginid to represent that)Will you have a single interface for uploading all the objects in a single go, which I don't think will work in this case?
Samuel
As most business users are very used to excel:- I would use one excel workbook with severall sheets. One upload.- User sheet has a column with a user number, unique for this import. Can be referenced from other sheets e.g. addresses ...
tkr
I would probably go for loginid which is going to be unique in my case, so User1 will have a row in User sheet and 2 in Address sheet, 1 row in Phone sheet, 3 rows in Email sheet.
Samuel
With respect to my point [3] above, assuming you have 50 entries during initial upload, how do you accomodate modifications to say User20 and User25 and say deletion of User30 and addition of 10 new users 51-60. Do you add additional metadata to denote this in the excel sheet or would you let the persistence layer handle this. Am looking for best practices here.
Samuel
I would not offer update or delete. I would only provide insert for initial uploads.But if you are going this way, I would use an extra meta column I/D/U only on user table. This meta column on all tables have confusing semantics. What is User1 D, User1.Address1 I ...
tkr
A: 

With DataNucleus you can map your class(es) that equates to the Excel data using JPA annotations, and load it up into your application. This can then be persisted into any other types of datastore that you require.

DataNucleus
@Andy - Can you point me to the docs for these annotations which will equate to excel data?
Samuel
Well you use standard JPA annotations, so look at http://www.datanucleus.org/products/accessplatform_2_1/jpa/annotations.htmland then we have some to control the column positioning in the Excel spreadsheet http://www.datanucleus.org/products/accessplatform_2_1/excel/mapping.html
DataNucleus
Removed signature as per the [official policy](http://stackoverflow.com/faq). Thanks.
Pascal Thivent
A: 

Are there any tools / APIs which abstract some of these needs for both importing / exporting?

There is DbUnit which now also supports an excel based dataset.

Pascal Thivent
@Pascal, dbunit supporting xls seems to be good. But I am not sure if the end users will be comfortable setting foriegn key identifier values, which they might not be aware of.
Samuel
@Samuel: You're right, dbunit doesn't abstract foreign keys (and I don't have an easy solution to create links without setting PK/FK).
Pascal Thivent