Table column name camel case conversion

910 views
Skip to first unread message

DTK

unread,
Jun 19, 2017, 7:04:02 AM6/19/17
to Ebean ORM
Hello,

I think there might be an issue with code converting column names to camel case.
I have the following SQL query:

SELECT
TYPE_ID,
SELL_ORDER_ID,
PROFIT ...

and corresponding entity

@Entity
@Sql
public class ResultOrder {

 
private Integer typeId;
 
private Integer sellOrderId;
 
private Double profit;
..........

After conversion of column names to properties we have the following results:
  • TYPE_ID -> typeId
  • SELL_ORDER_ID -> sellOrderId
  • PROFIT -> PROFIT

As you can see resulted property name does not match field name.

I looked through the code and found that if table column name contains no underscores it is left untouched.



public class CamelCaseHelper {

 
/**
   * To camel from underscore.
   *
   * @param underscore the underscore
   * @return the string
   */
  public static String toCamelFromUnderscore(String underscore) {

   
String[] vals = underscore.split("_");
   
if (vals.length == 1) {
     
return underscore;
   
}
..........


Test for this class shows that it works as originally intended:

public class CamelCaseHelperTest {

..........

 
@Test
  public void when_already_camel() throws Exception {
   
assertEquals(CamelCaseHelper.toCamelFromUnderscore("helloThere"), "helloThere");
   
assertEquals(CamelCaseHelper.toCamelFromUnderscore("helloThereJim"), "helloThereJim");
   
assertEquals(CamelCaseHelper.toCamelFromUnderscore("hello"), "hello");
   
assertEquals(CamelCaseHelper.toCamelFromUnderscore("HELLO"), "HELLO");
 
}

I really don't understand why it does not convert upper-case names to lower-case.
Is there any reason for that?

Rob Bygrave

unread,
Jun 19, 2017, 7:43:43 AM6/19/17
to ebean@googlegroups
why it does not convert upper-case names to lower-case.

Hmmm ... I'm not sure there is a good reason for that sure not sure about that.



> SELECT ... PROFIT ...

So you are using  findNative()  or RawSql or something like that ... and SELECT ... PROFIT ... isn't mapping the the bean you have above right.  Which mechanism are you using?  findNative() or ...





--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

DTK

unread,
Jun 19, 2017, 8:05:45 AM6/19/17
to eb...@googlegroups.com
I'm using RawSql.
Here is some code:

RawSql rawSql = RawSqlBuilder.parse(sql_select_search).create();

Query<ResultOrder> query = ebeanServer.find(ResultOrder.class)
   
.setParameter("cargo_volume", cargoVolume)
   
.setParameter("tax_rate", taxRate)
   
.setRawSql(rawSql);

return query.findList();

And it results in
javax.persistence.PersistenceException: Property [PROFIT] not found on *.ResultOrder
at io.ebeaninternal.server.query.CQueryBuilder.createRawSqlSqlTree(CQueryBuilder.java:428)
at io.ebeaninternal.server.query.CQueryBuilder.createSqlTree(CQueryBuilder.java:357)
at io.ebeaninternal.server.query.CQueryBuilder.buildQuery(CQueryBuilder.java:310)
at io.ebeaninternal.server.query.CQueryEngine.findMany(CQueryEngine.java:338)
at io.ebeaninternal.server.query.DefaultOrmQueryEngine.findMany(DefaultOrmQueryEngine.java:117)
at io.ebeaninternal.server.core.OrmQueryRequest.findList(OrmQueryRequest.java:356)
at io.ebeaninternal.server.core.DefaultServer.findList(DefaultServer.java:1497)
at io.ebeaninternal.server.querydefn.DefaultOrmQuery.findList(DefaultOrmQuery.java:1239)



понедельник, 19 июня 2017 г., 15:43:43 UTC+4 пользователь Rob Bygrave написал:
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+un...@googlegroups.com.

Rob Bygrave

unread,
Jun 19, 2017, 5:15:42 PM6/19/17
to ebean@googlegroups
Thanks.  I'll have a look a little later ... I suspect the existing tests use lower case SQL and don't cover this case etc.  I see you have logged a issue for it so that is good.

Cheers, Rob.

On 20 June 2017 at 00:05, DTK <dtkc...@gmail.com> wrote:
Here is a code:

RawSql rawSql = RawSqlBuilder.parse(sql_select_search).create();

Query<ResultOrder> query = ebeans().find(ResultOrder.class)

   
.setParameter("cargo_volume", cargoVolume)
   
.setParameter("tax_rate", taxRate)
   
.setRawSql(rawSql);

return query.findList();
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages