Bit of a bump for this topic. I've got so far but hopefully someone can give me a hand getting over that final hurdle.
I've gotten over my table naming problem using a NamingStrategy. Here's the code I'm using:
Code:
public String tableName(String tableName) {
String result = tableName;
if (tableName != null && tableName.endsWith(WILDCARD)) {
Calendar cal = Calendar.getInstance();
int imonth = cal.get(Calendar.MONTH)+1;
String month = (imonth < 10 ? "0"+ imonth : ""+ imonth);
String year = "" + cal.get(Calendar.YEAR);
result = result.substring(0, result.length() - 1) + year + month;
}
return result;
}
So if I have a entity like...
Code:
@Entity
@Table(name = "search_log_*")
public class LogEntry implements ILogEntry {
...
}
When it hits the DB it will actually be looking for a table called search_log_200708. That's great and what I want.
The trouble is that once the month ticks over, the table name won't match any table that exists in the table. It won't have been created yet.
Does anyone have any tips on how I could get Hibernate to automatically recreate the table in an efficient way?