API 변경사항

BytecodeProvider extension

  • 하이버네이트의 바이트코드 처리에 필요한 라이브러리를 추가할 수 있는 기능을 추가했다. 이전에는 CGLIB만 사용했는데, 이제는 CGLIB과 Javassist 중에 하나로 선택할 수 있다.

행동 변경사항

Non-transactional access

  • FlushMode.AUTO는 Session내의 변경을 모두 SQL을 실행해서 반영한다. 트랜잭션 범위가 아닐 경우에 auto flush는 생략된다.
  • Second has to do with identifiers generated via an
    "in-database" strategy (the so-called post-insert id generators). Saves
    to such entities in previous versions caused an immediate SQL INSERT to
    be issued in order to determine the generated identifier value.
    Starting with 3.2, these INSERTS will be delayed when done outside of a
    transaction.

쿼리 언어 변경사항

Implicit joins are more deterministic

<class name='Currency' lazy='false'>
....
</class>

<class name='Asset'>
<id name='id' ... </id>
<many-to-one name='currency' class='Currency' fetch='select'/>
</class>
  • select a.id, a.currency from Asset a 이런 쿼리는 inner join을 생성한다.
  • select a.id, c from Asset a left join a.currency as c 이렇게 해야 currency가 Null Asset도 전부 가져온다.

Path expressions joining across a collection throw exception

  • select f.bars.baz from Foo f 이런 네비게이션은 이제 에러난다.
  • select b.baz from Foo f join f.bars b 이렇게 써야 한다.

Changed aggregation (count, sum, avg) function return types

  • 스펙에 맡게 리턴타입이 바꼈다.
  • COUNT는 Long을 반환한다.
  • MAX와 MIN은 적용된 필드 타입을 반환한다.
  • AVG는 Double을 반환한다.
  • SUM은 정수타입이 경우에는 Long을 반환한다. 실수일 경우에는 Double, BidInteger일 경우에는 BidInteger, BigDecimal일 경우에는 BidDecimal.
  • 이전 타입을 쓰려면 다음의 코드를 추가한다.
Configuration classicCfg = new Configuration(); 
classicCfg.addSqlFunction( "count", new ClassicCountFunction());
classicCfg.addSqlFunction( "avg", new ClassicAvgFunction());
classicCfg.addSqlFunction( "sum", new ClassicSumFunction());
SessionFactory classicSf = classicCfg.buildSessionFactory();

Improved parameter type guessing

  • 이전에는 파라미터의 타입을 넘어온 값으로 판단했는데, 이제는 쿼리르 보고 판단한다.

Expanded component support

  • First is the ability to bind complete components as parameter values.
Name name = new Name();
name.setFirst( "John" );
name.setLast( "Doe" );
List johnDoes = session.createQuery( "from Person where name = :name" )
.setParameter( "name", name )
.list();
  • ANSI SQL 처럼 "row balue contructor"를 사용할 수 있다.
List johnDoes = session.createQuery( "from Person where name = ('John', 'Doe')" ).list();

Improved boolean literal and parameter handling

  • List pregs = session.createQuery( "from Animal where pregnant = true" ).list(); 이런 쿼리에서의 true 역시 쿼리를 분석하여 SQL을 만들어 낸다.

Native SQL 쿼리 변경사항

Sequence of return values from native sql queries (createSQLQuery() and getNamedQuery())

  • 이전에는 scalar 먼저, entity는 그 다음 순으로 반환했다.
  • 3.2에서 그 순서는 맵핑이나 코드에 있는 것으르 따른다.
  • 따라서 다음의 코드는 에러가 나지 않지만, 만약에 Entity를 먼저 add했으면 에러가 날 것이다.
List result = s.createSQLQuery("select o.*, o.value as anumber from ORDER as o").addScalar("anumber").addEntity(Order.class).list();
Object[] row = (Object[])result.get(0);
Integer number = (Integer)row[0];
Order order = (Order)row[1];

Stored procedures no longer require OUT parameter

  • 이전에는 영향을 받는 row의 수를 반환하는 out 파라미터를 필요로 했었는데 이젠 필수사항이 아니다.
  • check 속성에 none, count, param 을 사용할 수 있다.