gpt4 book ai didi

java - org.hibernate.MappingException : Could not determine typ

转载 作者:行者123 更新时间:2023-11-30 04:15:28 26 4
gpt4 key购买 nike

我收到此错误。

org.hibernate.MappingException: Could not determine type for: dom.Whore, at table:        Message, for columns: [org.hibernate.mapping.Column(receiver)]

这是映射到表中的类。

package dom;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import org.hibernate.annotations.GenericGenerator;
import org.springframework.stereotype.Component;

@Component
@Entity
public class Message {

private Whore sender;
private Whore receiver;
private Date date = new Date();
private String messageText;
private Boolean read;
private long id;

public Message(){}

public Message(Whore sender, Whore receiver) {
this.sender = sender;
this.receiver = receiver;
}

public Whore getSender() {
return sender;
}

public void setSender(Whore sender) {
this.sender = sender;
}
public Whore getReceiver() {
return receiver;
}

public void setReceiver(Whore receiver) {
this.receiver = receiver;
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}
public String getMessageText() {
return messageText;
}

public void setMessageText(String messageText) {
this.messageText = messageText;
}

public Boolean getRead() {
return read;
}

public void setRead(Boolean read) {
this.read = read;
}

@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy="increment")
public long getId() {
return id;
}

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

这是无法确定其类型的类。

package dom;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;


import org.hibernate.annotations.GenericGenerator;
import org.springframework.stereotype.Component;


@Component
@Entity
public class Whore {



private String username;
private String password;
private String email;
private List<Whore> friends = new ArrayList<Whore>();
private int reputation;
private long id;
private List<Message> messages = new ArrayList<Message>();



public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}

public int getReputation() {
return reputation;
}

public void setReputation(int reputation) {
System.out.println("in set reputation : " + reputation);
this.reputation = this.reputation + reputation;
System.out.println("new repuration : " + this.reputation);
}

public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy="increment")
public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}

@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
public List<Whore> getFriends() {
return friends;
}
public void setFriends(List<Whore> friends) {
this.friends = friends;
}

public void addFriend(Whore friend) {
getFriends().add(friend);
}

public void removeFriend(Whore friend) {
getFriends().remove(friend);
}

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
public List<Message> getMessages() {
return messages;
}

public void setMessages(List<Message> messages) {
this.messages = messages;
}

public void addMessage(Message message) {
getMessages().add(message);
}
}

我在很多帖子中读到,这与不同时在字段和 getter 上设置注释有关。但正如您所看到的,这不是原因。我被难住了。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">

<context:component-scan base-package="/dom" />
<context:component-scan base-package="/dao" />
<context:component-scan base-package="/controllers" />
<context:component-scan base-package="/services" />
<context:component-scan base-package="/security" />
<tx:annotation-driven />
<mvc:annotation-driven />

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/culturewhore" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="/" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<util:list id="beanList">
<ref bean="mappingJacksonHttpMessageConverter" />
</util:list>
</property>
</bean>

<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" p:maxUploadSize="1000000" />

<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />


</beans>

此外,我刚刚尝试在发送者和接收者 setter/getter 上使用@ManyToOne。但这没有任何区别。

最佳答案

您尚未将消息映射到消息内的妓女关系。应该是:

@ManyToOne
public Whore getSender() {
return sender;
}


@ManyToOne
public Whore getReceiver() {
return receiver;
}

注释:您不应将实体注释/使用为@Component

关于java - org.hibernate.MappingException : Could not determine typ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18509591/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com