Skip to content

Commit

Permalink
fixed #302
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobe91 committed Dec 14, 2016
1 parent ddd0600 commit 3c3e96a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,24 @@ public void testValuesEntityFunctionInCte() {
assertNull(resultList.get(0).get(1));
}

@Test
// NOTE: Entity joins are supported since Hibernate 5.1, Datanucleus 5 and latest Eclipselink
@Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class })
public void testValuesEntityFunctionWithCteEntity() {
CriteriaBuilder<Tuple> cb = cbf.create(em, Tuple.class);
cb.setProperty(ConfigurationProperties.VALUES_CLAUSE_FILTER_NULLS, "false");

cb.fromValues(PersonCTE.class, "cteValues", 2)
.select("cteValues.id")
.where("cteValues.id").isNotNull();

// Empty values
final PersonCTE personCTE = new PersonCTE();
personCTE.setId(1L);
cb.setParameter("cteValues", Arrays.asList(personCTE));
List<Tuple> resultList = cb.getResultList();
assertEquals(1, resultList.size());

assertEquals(personCTE.getId(), resultList.get(0).get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactor
}

serviceRegistry.locateServiceBinding(PersisterClassResolver.class).setService(new CustomPersisterClassResolver());
serviceRegistry.locateServiceBinding(Database.class).setService(new SimpleDatabase(metadata.getDatabase().getDefaultNamespace().getTables().iterator()));
serviceRegistry.locateServiceBinding(Database.class).setService(new SimpleDatabase(metadata.getDatabase().getDefaultNamespace().getTables().iterator(), sessionFactory.getDialect(), metadata));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactor
}

serviceRegistry.locateServiceBinding(PersisterClassResolver.class).setService(new CustomPersisterClassResolver());
serviceRegistry.locateServiceBinding(Database.class).setService(new SimpleDatabase(metadata.getDatabase().getDefaultNamespace().getTables().iterator()));
serviceRegistry.locateServiceBinding(Database.class).setService(new SimpleDatabase(metadata.getDatabase().getDefaultNamespace().getTables().iterator(), sessionFactory.getDialect(), metadata));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.blazebit.persistence.impl.hibernate;

import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Table;

import java.util.Collections;
Expand All @@ -32,11 +35,19 @@ public class SimpleDatabase implements Database {

private final Map<String, Table> tables;

public SimpleDatabase(Iterator<Table> iter) {
public SimpleDatabase(Iterator<Table> iter, Dialect dialect, Mapping mapping) {
Map<String, Table> map = new HashMap<String, Table>();
while (iter.hasNext()) {
Table t = iter.next();
map.put(t.getName(), t);
if (t.getSubselect() != null) {
map.put("( " + t.getSubselect() + " )", t);
Iterator<Column> columnIter = t.getColumnIterator();
while (columnIter.hasNext()) {
final Column column = columnIter.next();
column.getSqlType(dialect, mapping);
}
}
}
this.tables = Collections.unmodifiableMap(map);
}
Expand Down

0 comments on commit 3c3e96a

Please sign in to comment.