2017-01-24 5 views
0

Ich versuche, eine ... ContainingIgnoreCase JPA-Abfrage zu verwenden, um die Informationen aus drei verwandten Objekten zu extrahieren: Profil (ID), Profil_Interesse (Profil_ID und Zins_ID) und Interessen (ID).ContainingIgnoreCase Hibernate JPA-Fehler

In meinem Dienst I

@Service public class Searchservice rufen {

@Autowired 
private ProfileDao profileDao; 


public List<SearchResult> search(String text) { 
    return profileDao.findByInterestsNameContainingIgnoreCase(text).stream().map(SearchResult::new).collect(Collectors.toList()); 
} 

}

Dann ist mein DAO führt es aus:

blockieren @Repository Zitat öffentliche Schnittstelle ProfileDao erweitert CrudRepository {

Profile findByUsuario(Usuario usuario); 

List<Profile> findByInterestsNameContainingIgnoreCase(String text); 

}

Profil Objekt:

package music.bolo.domain.entity; 

import java.nio.file.Path; 
import java.nio.file.Paths; 
import java.util.Set; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.FetchType; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.JoinColumn; 
import javax.persistence.JoinTable; 
import javax.persistence.ManyToMany; 
import javax.persistence.OneToOne; 
import javax.persistence.OrderColumn; 
import javax.persistence.Table; 

import org.owasp.html.PolicyFactory; 

import music.bolo.domain.dto.FileInfo; 

@Entity 
@Table(name = "profile") 
public class Profile { 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    @Column(name = "id") 
    private long id; 

    @OneToOne(targetEntity = Usuario.class) 
    @JoinColumn(name = "user_id", nullable = false) 
    private Usuario usuario; 

    @Column(name = "about", length = 5000) 
    private String about; 

    @Column(name = "photo_directory", length = 10) 
    private String photoDirectory; 

    @Column(name = "photo_name", length = 10) 
    private String photoName; 

    @Column(name = "phot_extension", length = 5) 
    private String photoExtension; 

    @ManyToMany(fetch = FetchType.EAGER) 
    @JoinTable(name = "profile_interests", joinColumns = { @JoinColumn(name = "profile_id") }, inverseJoinColumns = { 
      @JoinColumn(name = "interest_id") }) 
    @OrderColumn(name = "display_order") 
    private Set<Interest> interests; 

    public Profile() { 
    } 

    public Profile(Usuario usuario) { 
     this.usuario = usuario; 
    } 

    public long getId() { 
     return id; 
    } 

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

    public Usuario getUsuario() { 
     return usuario; 
    } 

    public void setUsuario(Usuario usuario) { 
     this.usuario = usuario; 
    } 

    public String getAbout() { 
     return about; 
    } 

    public void setAbout(String about) { 
     this.about = about; 
    } 

    public String getPhotoDirectory() { 
     return photoDirectory; 
    } 

    public void setPhotoDirectory(String photoDirectory) { 
     this.photoDirectory = photoDirectory; 
    } 

    public String getPhotoName() { 
     return photoName; 
    } 

    public void setPhotoName(String photoName) { 
     this.photoName = photoName; 
    } 

    public String getPhotoExtension() { 
     return photoExtension; 
    } 

    public void setPhotoExtension(String photoExtension) { 
     this.photoExtension = photoExtension; 
    } 

    // Create a profile that is suitable for displaying via JSP 
    public void safeCopyFrom(Profile other) { 
     if (other.about != null) { 
      this.about = other.about; 
     } 
     if (other.interests != null) { 
      this.interests = other.interests; 
     } 
    } 

    // Create a profile sanitized for saving 
    public void safeMergeFrom(Profile webProfile, PolicyFactory htmlPolicy) { 

     if (webProfile.about != null) { 
      this.about = htmlPolicy.sanitize(webProfile.about); 
     } 
    } 

    public void setPhotoDetails(FileInfo info) { 

     photoDirectory = info.getSubDirectory(); 
     photoExtension = info.getExtension(); 
     photoName = info.getBasename(); 
    } 

    public Path getPhoto(String baseDirectory) { 
     if (photoName == null) { 
      return null; 
     } 
     return Paths.get(baseDirectory, photoDirectory, photoName + "." + photoExtension); 
    } 

    public Set<Interest> getInterests() { 
     return interests; 
    } 

    public void setInterests(Set<Interest> interests) { 
     this.interests = interests; 
    } 

    public void addInterest(Interest interest) { 
     interests.add(interest); 
    } 

    public void removeInterest(String interestName) { 
     interests.remove(new Interest(interestName)); 
    } 

    @Override 
    public String toString() { 
     return "Profile [id=" + id + ", usuario=" + usuario + ", about=" + about + ", photoDirectory=" + photoDirectory 
       + ", photoName=" + photoName + ", photoExtension=" + photoExtension + ", interests=" + interests + "]"; 
    } 

} 

Aber ... ich diese bekommen Fehler

2017-01-24 22: 06: 38,357 INFO 4656 --- [restartedMain] j.LocalContainerEntityManagerFactoryBean: Closing JPA EntityManagerFactory für 'default' Persistenzeinheit 2017.01.24 22: 06: 38,389 INFO 4656 - - [restartMain] o.apache.catalina.core.StandardService: Stoppen des Dienstes Tomcat 2017-01-24 22: 06: 38.404 WARN 4656 --- [ost-startStop-1] oacloader.WebappClassLoaderBase: Die Web-Anwendung [ROOT ] scheint einen Thread namens [Verbindungsaufräumungs-Thread abgebrochen] gestartet zu haben, konnte ihn jedoch nicht stoppen. Dies führt sehr wahrscheinlich zu einem Speicherleck. Stack-Trace thread: java.lang.Object.wait (Mutter Methode) java.lang.ref.ReferenceQueue.remove (Unknown Source) com.mysql.jdbc.AbandonedConnectionCleanupThread.run (AbandonedConnectionCleanupThread.java:43) 2017 -01-24 22: 06: 38,420 ERROR 4656 --- [restartedMain] osboot.SpringApplication: Anwendungsstart nicht gestartet

org.springframework.beans.factory.BeanCreationException: Error bean mit Namen Schaffung 'Indexcontroller': Die Injektion von autowired Abhängigkeiten fehlgeschlagen; Verschachtelte Ausnahme ist org.springframework.beans.factory.BeanCreationException: Feld konnte nicht automatisch aktiviert werden: private music.bolo.services.ProfileService music.bolo.controllers.IndexController.profileService; verschachtelte Ausnahme ist org.springframework.beans.factory.BeanCreationException: Fehler beim Erstellen der Bean mit dem Namen 'profileService': Die Injektion der autowired Abhängigkeiten ist fehlgeschlagen; Verschachtelte Ausnahme ist org.springframework.beans.factory.BeanCreationException: Feld konnte nicht autowire: music.bolo.domain.repository.ProfileDao music.bolo.services.ProfileService.profileDao; Verschachtelte Ausnahme ist org.springframework.beans.factory.BeanCreationException: Fehler beim Erstellen der Bean mit dem Namen 'profileDao': Aufruf der init-Methode fehlgeschlagen; verschachtelte Ausnahme ist java.lang.IllegalStateException: Illegaler Versuch, die Pfadquelle [null.interests] des Basistyps bei org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues ​​(AutowiredAnnotationBeanPostProcessor.java:334) ~ [Quell-Bohnen -4.2.4.RELEASE.jar: 4.2.4.RELEASE]

+0

Ihr Profil Zuordnungsdatei hinzufügen. Ist auch die vollständige Stapelverfolgung? –

Antwort

0

Ich löste es ein Eingeborener Abfrage in meinem DAO:

Paket music.bolo.domain.repository;

importieren java.util.List;

import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository;

importieren music.bolo.domain.entity.Profile;

öffentliche Schnittstelle ProfileDaoQuery erweitert CrudRepository {

@Query(value = "SELECT * FROM profile " 
     + "INNER JOIN profile_interests ON profile.id = profile_interests.profile_id" 
     + " INNER JOIN interests ON profile_interests.interest_id=interests.id " 
     + "WHERE interests.interest_name like %?1%", nativeQuery = true) 
List<Profile> findByInterestNames(String text); 

}

+0

Dies funktioniert auch: https://stackoverflow.com/questions/33792288/springdatajpa-multiple-containingignorecase – Mike