即使已正确注入,Spring / Hibernate仍指向另一个实体

时间:2019-01-30 19:47:45

标签: java spring hibernate

我想检查是否从数据库中正确检索了我的数据。我有两个类Transaction和FixedTransaction,分别为Controller和DatabaseService。在fixedTransaction中,我有适当的吸气剂。

正在发生:

javax.el.PropertyNotFoundException: Property [fixedTransactionIdentity] not 
found on type [com.mybudget.entity.Transaction]

尽管这里是对FixedTransaction类的引用:

 <c:forEach var="fixedTransaction" items="${allFixedTransactions}">

我不知道哪里出了问题。

@Entity
@Table(name = "fixed_transaction")
    @NamedQueries({
    @NamedQuery(name ="get_all_fixed_transactions", query = "select ft from 
FixedTransaction ft")
})
public class FixedTransaction {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_fixed_transaction")
private int fixedTransactionId;

@Column(name = "amount")
private BigDecimal fixedMoneyAmount;

@Column(name = "begin_date")
private Date durationBeginDate;

@Column(name = "end_date")
private Date durationEndDate;

@Column(name = "comment")
private String transactionComment;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "id_user")
private User fixedTransactionUser;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "id_category")
private Category fixedTransactionsInCategory;

public FixedTransaction(){}

public FixedTransaction(BigDecimal fixedMoneyAmount, Date durationBeginDate, Date durationEndDate, String transactionComment) {
    this.fixedMoneyAmount = fixedMoneyAmount;
    this.durationBeginDate = durationBeginDate;
    this.durationEndDate = durationEndDate;
    this.transactionComment = transactionComment;
}

public int getFixedTransactionId() {
    return fixedTransactionId;
}

}

我的.jsp片段显示了两个表,但是我只注入FixedTransactions:

<p>
    <table>
        <thead>
        <tr>
            <th>ID</th>
            <th>Amount</th>
            <th>Flow  date</th>
            <th>Description</th>
        </tr>
        </thead>
        <tbody
        <c:forEach var="transaction" items="${allTransactionsList}">
            <tr>
                <td>${transaction.transactionId}</td>
                <td>${transaction.moneyAmount}</td>
                <td>${transaction.transactionDate}</td>
                <td>${transaction.description}</td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    </p>

    <p>
    <table>
        <thead>
        <tr>
            <th>ID</th>
            <th>Amount</th>
            <th>Begin Date</th>
            <th>End Date</th>
            <th>Comment</th>
        </tr>
        </thead>
        <tbody
        <c:forEach var="fixedTransaction" items="${allFixedTransactions}">
            <tr>
                <td>${fixedTransaction.fixedTransactionId}</td>
                <td>${fixedTransaction.fixedMoneyAmount}</td>
                <td>${fixedTransaction.durationBeginDate}</td>
                <td>${fixedTransaction.durationEndDate}</td>
                <td>${fixedTransaction.transactionComment}</td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    </p>

和用于固定交易的控制器:

import com.mybudget.services.DatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/fixedTransaction")
public class FixedTransactionController {

@Autowired
DatabaseService databaseService;

@GetMapping("/fixedList")
public String fixedTransactionsList(Model theModel){
theModel.addAttribute("allFixedTransactions",databaseService
.getAllFixedTransactions());
    return "test-main-page";
}
}

0 个答案:

没有答案