tags:

views:

289

answers:

2

I'm working on a project which parses information with a NLP library from classified ads on internet forums. After the processing I have ForSaleItem instances and all sorts of details like condition, price etc.

When I call the toString() method on these objects, it does not return a string stored in the object itself but rather looks up its own start and end point within the entire forum post and then extracts the text from there. (This is done so I can calculate proximity of individual bits of text).

I would like to use JPA to persist these objects to a RDBMS. After the processing I don't really care about the proximity stuff anymore, I just want to display the strings to the user. It would be an enormous waste if I'd persist the entire forum post and keep retrieving the actual text through the above method.

My question now: Should I enhance the original classes with String fields or should I create an entirely new class, ie. something like PersistentForSaleItem?

A: 

I would recommend creating a new item, that persists and contains only the pieces you are concerned with. This seems like it might be easiest, and would allow you to separate the concerns of gathering/manipulating the data and the final storage and display of the data. You could even have the persistent objects be created by passing in the other object during construction, and then use annotations/xml configurations to persist the object into the RDBMS.

Just my 2 cents.

aperkins
A: 

Looks like your ForSaleItem have several points really incompatible with what you want to persist :

  • complex retrieving process of the String

    -> unneeded after persistence.

  • multiple objets that would be persisted to multiples tables

    -> unnecessary complex and slow, while with only one objet you can store the String in a single table, and retrieve it more efficiently.

Therefore, I advise you use a different object for Persistence.

Note that it can be really simple to create, for example :

  • a class, no superclass, with annotation @Entity
  • an Long identifier field, with annotations @Id and @GeneratedValue
  • one String field, with getter (with @Column if you want a String length maximum different from the 256 default) and setter
  • an empty constructor (optional)

  • -
KLE