I tried to select all columns from the table MAGICNOTIFY_CARD_INFO
, so i wrote a code;
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(MagicnotifyApplication.class, args);
MagicnotifyCardInfoRepository magicnotifyCardInfoRepository =
context.getBean(MagicnotifyCardInfoRepository.class);
magicnotifyCardInfoRepository.findAll();
//SpringApplication.run(MagicnotifyApplication.class, args);
}
and this is the entity i wanted to select;
public class MagicnotifyCardInfoID implements Serializable {
@Column(name = "koname")
private String koname;
@Column(name = "name")
private String name;
@Column(name = "cardkingdom")
private String cardkingdom;
@Column(name = "cardkingdomfoil")
private String cardkingdomfoil;
@Column(name = "set")
private String set;
@Column(name = "setName")
private String setName;
@Column(name = "reldate")
private Date reldate;
@Column(name = "rarity")
private String rarity;
@Column(name = "uuid")
private String uuid;
@ManyToOne
private MagicnotifyUuidName magicnotifyUuidName;
@ManyToOne
private MagicnotifySetInfo magicnotifySetInfo;
}
public class MagicnotifyCardInfo implements Serializable {
@EmbeddedId
private MagicnotifyPriceID id;
}
public interface MagicnotifyCardInfoRepository extends JpaRepository<MagicnotifyCardInfo, Long> {
@Query(value = "SELECT * FROM MAGICNOTIFY_CARD_INFO", nativeQuery = true)
List<MagicnotifyCardInfo> findByAll();
List<MagicnotifyCardInfo> findAll();
}
but after querying, it tries to select other column item from table MAGICNOTIFY_PRICE;
public class MagicnotifyPriceID implements Serializable {
@Column(name = "foil")
private BigDecimal foil;
@Column(name = "normal")
private BigDecimal normal;
@Column(name = "date")
private Date date;
@Column(name = "key")
private String key;
@ManyToOne
private MagicnotifyUuidName id;
}
public class MagicnotifyPrice implements Serializable {
@EmbeddedId
private MagicnotifyPriceID id;
}
I'm not sure why it happens from differently mapped two tables; how can i select from initial table MAGICNOTIFY_CARD_INFO and select from its columns?
CodePudding user response:
First of all, you have not mentioned any primary key using @Id annotation inside either of your MagicnotifyCardInfoID class or MagicnotifyPriceID class Secondly, you have given same @EmbeddedId fields "MagicnotifyPriceID id" in both the below classes
public class MagicnotifyCardInfo implements Serializable {
@EmbeddedId
private MagicnotifyPriceID id;
}
public class MagicnotifyPrice implements Serializable {
@EmbeddedId
private MagicnotifyPriceID id;
}
I don't see @Embeddable used anywhere in your program Please refer https://www.baeldung.com/jpa-embedded-embeddable
public interface MagicnotifyCardInfoRepository extends JpaRepository<MagicnotifyCardInfo, Long> {
@Query(value = "SELECT * FROM MAGICNOTIFY_CARD_INFO", nativeQuery = true)
List<MagicnotifyCardInfo> findByAll();
List<MagicnotifyCardInfo> findAll();
}
In the above class you are passing "JpaRepository<MagicnotifyCardInfo, Long>" Long as the data type of a primary key in your entity "MagicnotifyCardInfo" which does not even exist.
Please fix these and try again.