Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.hibernate.search.bugs;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.MapKeyEnumerated;
import javax.persistence.OneToMany;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
public class MetaData {

@Id
@GeneratedValue
@Column(name = "ID")
private int id;

public Collection<UntypedDataEntity> getMap() {
return map;
}

public void setMap(Collection<UntypedDataEntity> map) {
this.map = map;
}

public void addData(UntypedDataEntity data) {
map.add(data);
}

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@MapKeyEnumerated(value = EnumType.ORDINAL)
@JoinTable(joinColumns = @JoinColumn(name = "METADATA_ID"))
@Fetch(FetchMode.SELECT)
private Collection<UntypedDataEntity> map;


public MetaData() {
map = new ArrayList<>();
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public void printEntities() {
for(UntypedDataEntity entity : map) {
System.out.println("Entity: "+entity.toString());
}
}





}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.hibernate.search.bugs;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

import org.hibernate.search.engine.backend.types.Projectable;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;

@Entity
@DiscriminatorValue("2")
@Indexed
public class PersonEntity extends UntypedDataEntity {

private String name;
private String addressLine;
private String zip;
private String country;

public PersonEntity(String string, String name, String addressLine, String zip, String country) {
super(string);
this.name = name;
this.addressLine = addressLine;
this.zip = zip;
this.country = country;
}

public PersonEntity() {

}

@Column(columnDefinition = "varchar(4000)")
@FullTextField(analyzer = "default",projectable = Projectable.YES)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(columnDefinition = "varchar(4000)")
@FullTextField(analyzer = "default",projectable = Projectable.YES)
public String getAddressLine() {
return addressLine;
}
public void setAddressLine(String addressLine) {
this.addressLine = addressLine;
}
@Column(columnDefinition = "varchar(4000)")
@FullTextField(analyzer = "default",projectable = Projectable.YES)
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
@Column(columnDefinition = "varchar(4000)")
@FullTextField(analyzer = "default",projectable = Projectable.YES)
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}

public String toString() {
return "Person - Name: "+name+" Adress: "+addressLine+" Zip: "+zip+" Country: "+country;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.hibernate.search.bugs;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Id;

import org.hibernate.search.engine.backend.types.Projectable;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;

@Entity
@DiscriminatorValue("3")
@Indexed
public class SubjectEntity extends UntypedDataEntity {


private String subject;

public SubjectEntity() {

}

protected SubjectEntity(String string, String subject) {
super(string);
this.subject = subject;
}

@Column(columnDefinition = "varchar(4000)")
@FullTextField(analyzer = "default",projectable = Projectable.YES)
public String getSubject() {
return subject;
}

public void setSubject(String subject) {
this.subject = subject;
}

public String toString() {
return "Subject - subject: "+subject;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.hibernate.search.bugs;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;

import org.hibernate.search.engine.backend.types.Projectable;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;

@Entity
@Indexed(index = "UntypedData")
@Table(name = "UntypedData", indexes = { @Index(name = "index_string", columnList = "string") })
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(columnDefinition = "char(2)", name = "UntypedDataType", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("1")
public class UntypedDataEntity {

int id;
String string;

public UntypedDataEntity(String string) {
this.string = string;
}
public UntypedDataEntity() {

}

@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}

@Column(columnDefinition = "varchar(4000)")
@FullTextField(analyzer = "default",projectable = Projectable.YES)
public String getString() {
return string;
}
public void setString(String string) {
this.string = string;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.search.mapper.orm.Search;
Expand All @@ -15,33 +20,41 @@ public class YourIT extends SearchTestBase {

@Override
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[]{ YourAnnotatedEntity.class };
return new Class<?>[]{SubjectEntity.class, UntypedDataEntity.class, PersonEntity.class, MetaData.class,};
}

@Test
public void testYourBug() {
try ( Session s = getSessionFactory().openSession() ) {
YourAnnotatedEntity yourEntity1 = new YourAnnotatedEntity( 1L, "Jane Smith" );
YourAnnotatedEntity yourEntity2 = new YourAnnotatedEntity( 2L, "John Doe" );

Transaction tx = s.beginTransaction();
s.persist( yourEntity1 );
s.persist( yourEntity2 );
tx.commit();
}

try ( Session session = getSessionFactory().openSession() ) {
SearchSession searchSession = Search.session( session );

List<YourAnnotatedEntity> hits = searchSession.search( YourAnnotatedEntity.class )
.where( f -> f.match().field( "name" ).matching( "smith" ) )
.fetchHits( 20 );

assertThat( hits )
.hasSize( 1 )
.element( 0 ).extracting( YourAnnotatedEntity::getId )
.isEqualTo( 1L );
try ( Session s = getSessionFactory().openSession() ) {
SubjectEntity yourEntity1 = new SubjectEntity( "string","Hibernate" );
PersonEntity yourEntity2 = new PersonEntity("string", "John","adress","zip","country");
MetaData md = new MetaData();
md.addData(yourEntity1);
md.addData(yourEntity2);
Transaction tx = s.beginTransaction();
s.persist( md );
tx.commit();
}

try ( Session session = getSessionFactory().openSession() ) {
SearchSession searchSession = Search.session( session );

List<UntypedDataEntity> hits = searchSession.search( UntypedDataEntity.class )
.where(f -> f.bool()
.must(f.match().fields( "subject" ).matching( "Hibernate"))
.must(f.match().fields( "name" ).matching( "John")))
.fetchHits(20);
System.out.println("#############################################");
for(UntypedDataEntity e : hits) {
System.out.println(e.toString());
}
System.out.println("##############################################");

assertThat( hits )
.hasSize( 1 )
.element( 0 ).extracting( UntypedDataEntity::getId )
.isEqualTo( 1 );
}
}
}

}