0

Here is what I got.the Table annotation set the table name to cbhistory_article, but the ormlite's TableInfo get the table name is article.

enter image description here

How can I get the right thing ?

In com.j256.ormlite.table.DatabaseTableConfig#extractTableName will find out, com.j256.ormlite.misc.JavaxPersistence#getEntityName only get the entity name rather than table name. But why ?

According to this, I think consider use the Table name is better or both of Table and Entity name.

Community
  • 1
  • 1
wener
  • 7,191
  • 6
  • 54
  • 78

2 Answers2

1

The @Table annotation set the table name to cbhistory_article, but the ormlite's TableInfo get the table name is article.

You didn't provide the code that you are using to define the entity but I assume it was something like:

@Entity
@Table(name = "cbhistory_article")
public class Article {
   ...

Unfortunately, at this time ORMLite does not support the @Table annotation. I've added the code for this to trunk and it will be in version 4.49. Sorry for the miss. Right now it only listens to the name field however. Do you need more support for other fields?

To get it to work, use the name field on the @Entity annotation:

@Entity(name = "cbhistory_article")
public class Article {
   ...
Gray
  • 115,027
  • 24
  • 293
  • 354
0

This is my way to work around.

@Inject
private void initDao(DataSource dataSource, @Named("jdbc.url") String url) throws SQLException
{
    setConnectionSource(new DataSourceConnectionSource(dataSource, url));

    DatabaseTableConfig<T> config = DatabaseTableConfig.fromClass(getConnectionSource(), dataClass);
    config.setTableName(getTableName());
    setTableConfig(config);

    initialize();
}

private String getTableName()
{
    Table table = dataClass.getAnnotation(Table.class);
    if (table == null || Strings.isNullOrEmpty(table.name()))
        return DatabaseTableConfig.extractTableName(dataClass);

    return table.name();
}
wener
  • 7,191
  • 6
  • 54
  • 78