使用@Embedded类的“字段列表”中的未知列

时间:2019-03-29 23:33:47

标签: java spring jpa

我在使用Spring JPA时遇到问题。

这是我的域:

body {
    background-color: #010d91; 
    margin: 0;
}
#wrapper {
    width: 80%;
    margin: 0 auto;
    background-color: white;
    color: black;
}
h1 {
    font-size: 50px;
    text-align: center;
}
header {
    background-color: #5995f7;
    padding: 10px 10px 10px 10px;   
}
nav {
    background-color: #89c6ed;
    float: right;
    width: 150px;
    font-weight: bold;
    letter-spacing: 0.1em;
}
main {
    padding:10px 20px;
    color: #000000;
    display: block;
    overflow: auto;
}
h2 {
 color: #869dc7;
}
nav ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}
nav a {
    text-decoration: none;
    padding: 20px;
    display: block;
    background-color: #89c6ed;
    border-bottom: 1px solid #FFFFFF;
}
nav a:link {
    color:#ffffff
}
nav a:visited {
    color: #eaeaea;
}   
nav a:hover {
    color: #869dc7;
    background-color: #eaeaea;
}
footer {
    text-align: center;
    font-style: italic;
    font-size: small;
    padding-top: 5px;
    padding-bottom: 5px;
    background-color: #5995f7;
}

#content-wrapper {
    display: flex;
    flex-direction: row-reverse;    
}

这是我的嵌入式课程:

<!doctype html>
<html lang="en">
  <head>
    <title>Lighthouse Island Bistro</title>
    <link rel="stylesheet" type="text/css" href="tes.css">
    <meta charset="utf-8">
  </head>
  <body>
    <div id="wrapper">
      <header>
        <h1>Lighthouse Island Bistro</h1>
      </header>
      <div id="content-wrapper">
        <nav>
          <ul>
            <li><a href="index.html">Home</a></li>
            <li><a href="menu.html">Menu</a></li>
            <li><a href="map.html">Map</a></li>
            <li><a href="contact.html">Contact</a></li>
          </ul>
        </nav>
        <main>
          <h2>Locally Roasted Free-Trade Coffe</h2>
          <p>Indulge in the aroma of freshly ground coffe. Speciality drinks are available hot or cold</p>
          <h2>Speciality Pastries</h2>
          <p>Enjoy a selection of our fresh-baked, organic pastries, including fresh-fruit muffins, scones, croissants, and cinnamon rolls.</p>
          <h2>Lunchtime is Anytime</h2>
          <p>Savor delicios wraps and sandwiches on hearty, whole-grain breads with locally-grown salad, fruit, and vegetables.</p>
          <h2>Panoramic View</h2>
          <p>Take in some scenery! <br> The top of our lighthouse offers a panoramic view of the countryside. Challenge your friends to climb our     
    100-stair tower.</p>
        </main>
      </div>
      <footer>
        Copyright &copy; 2016
      </footer>
    </div>
  </body>
</html>

这是我为测试环境配置schema.sql的方式:

@Entity
public class Courier {

    @Id
    private int id;

    @Enumerated(EnumType.STRING)
    private VehicleType vehicle;

    @Enumerated(EnumType.STRING)
    private Status status;

    @Embedded
    private Location location;

    public Courier(int id, Location location, VehicleType vehicle, Status status) {
        this.id = id;
        this.location = location;
        this.vehicle = vehicle;
        this.status = status;
     }

这是我的测试(我知道这没有任何作用,仅适用于HSQLDB):

@Embeddable
public class Location {

    private double coorx;
    private double coory;

    public Location(double coorx, double coory) {
        this.coorx = coorx;
        this.coory = coory;
    }

当我执行此操作时,它会抛出此错误:

DROP TABLE courier
DROP TABLE vehicle

CREATE TABLE courier (
    id INT PRIMARY KEY,
    vehicle VARCHAR(100),
    status VARCHAR(100),
    coorx DOUBLE,
    coory DOUBLE
);

CREATE TABLE vehicle (
    id VARCHAR(100) PRIMARY KEY,
    weight_limit BIGINT,
    distance_limit BIGINT
);

INSERT INTO courier VALUES (1, 1, 1, 'CAR', 'IDLE');
INSERT INTO courier VALUES (2, 13, 34, 'MOTORCYCLE', 'DELIVERING');

INSERT INTO vehicle VALUES ('BIKE', 15, 5);
INSERT INTO vehicle VALUES ('MOTORCYCLE', 30, 10);
INSERT INTO vehicle VALUES ('CAR', 100, 0);
INSERT INTO vehicle VALUES ('TRUCK', 0, 0);

无法识别coorx列。 我做了很多研究,但我不明白自己在做错什么。

courierService调用@RunWith(SpringRunner.class) @SpringBootTest public class WebserverApplicationTests { @Autowired CourierService courierService; @Test public void test(){ List<Courier> couriers = courierService.findAll(); } } 2019-03-29 20:12:00.969 INFO 87347 --- [main] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory Hibernate: select courier0_.id as id1_0_, courier0_.coorx as coorx2_0_, courier0_.coory as coory3_0_, courier0_.status as status4_0_, courier0_.vehicle as vehicle5_0_ from courier courier0_ 2019-03-29 20:12:01.207 WARN 87347 --- [main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1054, SQLState: 42S22 2019-03-29 20:12:01.207 ERROR 87347 --- [main] o.h.engine.jdbc.spi.SqlExceptionHelper : Unknown column 'courier0_.coorx' in 'field list' 扩展了courierRepository.findAll()

有什么主意吗?

0 个答案:

没有答案