嗨,我在hibernate中遇到了一个问题,即它没有将名为“ summoners”的实体映射到Postgre中现有的名为“ summoners”的表中

java - Spring Hibernate不将实体映射到PostGres中的现有表-LMLPHP


Postgre版本:9.2

Sts版本:4.4.2.RELEASE


summoners.java

package hello;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "summoners")
public class summoners {
    @Id
    @Column(name = "SummonerName")
    private String SummonerName;
    @Column(name = "SummonerEncryptedID")
    private String SummonerEncryptedID;
}


SummonerRepository.java

package hello;
import java.util.List;

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


// This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository
// CRUD refers Create, Read, Update, Delete

public interface SummonerRepository extends CrudRepository<summoners, Integer> {

}


GreetingController.java

package hello;

import java.util.concurrent.atomic.AtomicLong;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();
    @Autowired
    private SummonerRepository summonerRepository;


    @RequestMapping("/greeting")
    public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
        return new Greeting(counter.incrementAndGet(),
                            String.format(template, name));
    }

    @RequestMapping("/summoners")
    public Iterable<summoners> summoners() {
        return summonerRepository.findAll();
    }


}


固定

问题是postgre 9.2.0在以大写字母开头的列时遇到了问题...

最佳答案

很高兴听到它的修复。

除此之外,我可以看到

public interface SummonerRepository extends CrudRepository<summoners, Integer>


应该

public interface SummonerRepository extends CrudRepository<summoners, String>

09-10 20:20