开发者

Get first free number from column

I would like to get first number from column.

In column i have numbers:

1 2 3 4 6 8

So the first free number is: 5 Insert 5 to this column The second call should return: 7 insert 7 to this column Another call should return: 9 [...]

I know how to write this SQL, but the problem is that, this column is chart type. So its possible to be like this:

1 2 3 a b c 7 8 9

This is also not problem, i can use开发者_开发百科 some isNumeric function to filtered records, but i should do this in HQL.

My idea is something like this:

SELECT distinct min(value) FROM table WHERE number+1 NOT IN (SELECT charColumn FROM table)

Thanks


If you are aware how to write this in SQL, using one of following ways you can do achieve this by using hibernate.

  1. You can directly write the native sql query in hibernate by using createSqlQuery() method of session.
    Refer this URL for more details; http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querysql.html
  2. OR - Make a view of your Sql query and call it from your code by binding it with your entity class.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜