Question

I'm using Hibernates "Hibernate mapping files and POJOs from database" to transform tables to POJOs. The problem is that the table relations do not automatically create a "Set ..." property. What do I have to do to make Hibernate work with this?

Example table structure: Example table structure

Edit: So for example Stock has a property "Set StockDailyRecord". Hibernate should add them automatically. An example of what I mean can be found here: http://www.tutorialspoint.com/hibernate/hibernate_set_mapping.htm

Was it helpful?

Solution

It's the job of the developer to create the setters and getters for the java objects.

Assuming you have a field

private Set<Stock> stockDailyRecord;

Normally you would create a pair:

public Set<Stock> getStockDailyRecord();
public void setStockDailyRecord( Set<Stock> newRecordSet);

And then you would also normally create a convenience method

public void addDailyRecord( Stock newRecord)
{
    this.getStockDailyRecord().add(newRecord);
}

Hint: most IDEs will create the getter/setters for you after you define the fields.

OTHER TIPS

Typically, you only need a getter for relations.

  Set<StockDailyRecord> getStockDailyRecords() { return stockDailyRecords; }

and then

  StockDailyRecord aStockDailyRecord = ...
  stock.getStockDailyRecords().add(aStockDailyRecord);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top