0604 OneToMany全然… 'msgdata0_.mydata_id' in 'field list'

package com.tuyano.springboot;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.tuyano.springboot.repositories.MsgDataRepository;

@Controller
public class MsgDataController {
	
	@Autowired
	MsgDataRepository repository;
	
	@PersistenceContext
	EntityManager entityManager;
	
	MsgDataDaoImpl dao;

	@RequestMapping(value = "/msg", method = RequestMethod.GET)
	public ModelAndView msg(ModelAndView mav) {
		mav.setViewName("showMsgData");
		mav.addObject("title","Sample");
		mav.addObject("msg","MsgDataのサンプルです。");
		MsgData msgdata = new MsgData();
		mav.addObject("formModel", msgdata);
		List<MsgData> list = (List<MsgData>)dao.getAll();
		mav.addObject("datalist", list);
		return mav;
	}

	@RequestMapping(value = "/msg", method = RequestMethod.POST)
	public ModelAndView msgform(
			@Valid @ModelAttribute MsgData msgdata, 
			Errors result, 
			ModelAndView mav) {
		if (result.hasErrors()) {
			mav.setViewName("showMsgData");
			mav.addObject("title", "Sample [ERROR]");
			mav.addObject("msg", "値を再チェックしてください!");
			return mav;
		} else {
			repository.saveAndFlush(msgdata);
			return new ModelAndView("redirect:/msg");
		}
	}

	@PostConstruct
	public void init(){
		System.out.println("ok");
		dao = new MsgDataDaoImpl(entityManager);
	}
}
package com.tuyano.springboot;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;

@Entity
@Table(name = "msgdata")
public class MsgData {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column
	@NotNull
	private long id;

	@Column
	private String title;

	@Column(nullable = false)
	private String message;
	
	public long getId() {
		return id;
	}

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

	@ManyToOne
	private MyData mydata;

	public MsgData() {
		super();
		mydata = new MyData();
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public MyData getMydata() {
		return mydata;
	}

	public void setMydata(MyData mydata) {
		this.mydata = mydata;
	}
}
package com.tuyano.springboot;

import java.io.Serializable;
import java.util.List;
import com.tuyano.springboot.MyData;

public interface MyDataDao <T> extends Serializable{
	public List<MsgData> getAll();
}
package com.tuyano.springboot;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

@Entity
@Table(name="goods")
public class MyData {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column
	@NotNull
	private	long id;
	
	@Column(length = 50, nullable = false)
	private String name;
	
	@Column(length = 200, nullable = true)
	private String mail;
	
//	@Column(nullable = true)
//	private Integer age;
	
	@Column(nullable = true)
	private String memo;
	
	@OneToMany(cascade=CascadeType.ALL)
	@Column(nullable = true)
	private List<MsgData> msgdatas;
	
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getMail() {
		return mail;
	}
	public void setMail(String mail) {
		this.mail = mail;
	}
//	public Integer getAge() {
//		return age;
//	}
//	public void setAge(Integer age) {
//		this.age = age;
//	}
	public String getMemo() {
		return memo;
	}
	public void setMemo(String memo) {
		this.memo = memo;
	}
	public List<MsgData> getMsgdatas() {
		return msgdatas;
	}

	public void setMsgdatas(List<MsgData> msgdatas) {
		this.msgdatas = msgdatas;
	}
}
package com.tuyano.springboot;

import java.util.List;

public interface MsgDataDao<T> {
	public List<MsgData> getAll();
	public MsgData findById(long id);
}
package com.tuyano.springboot;

import java.util.List;

import javax.persistence.EntityManager;

import org.springframework.stereotype.Repository;

@SuppressWarnings("rawtypes")
@Repository
public class MsgDataDaoImpl implements MsgDataDao<MsgDataDao> {
	private EntityManager entityManager;

	public MsgDataDaoImpl() {
		super();
	}
	
	
	public MsgDataDaoImpl(EntityManager manager) {
		entityManager = manager;
	}
	

	@SuppressWarnings("unchecked")
	@Override
	public List<MsgData> getAll() {
		return entityManager
				.createQuery("from MsgData")
				.getResultList();
	}
	@Override
	public MsgData findById(long id) {
		return (MsgData)entityManager
				.createQuery("from MsgData where id = " 
				+ id).getSingleResult();
	}

}

2018/06/04
package com.tuyano.springboot.repositories;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.Repository;

import com.tuyano.springboot.MsgData;

@Repository
public interface MsgDataRepository extends JpaRepository {

}
この状態で
@Repositoryが「Repository is not an annotation type」とのエラー
→importするrepositoriesにすごくよく似たやつがいる
import org.springframework.data.repository.Repository; //☓
import org.springframework.stereotype.Repository; //○


======================================================================================
Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister

======================================================================================
→フィールドに対してsetterがない


======================================================================================
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'msgdata0_.mydata_id' in 'field list'
======================================================================================
https://stackoverflow.com/questions/27797806/com-mysql-jdbc-exceptions-jdbc4-mysqlsyntaxerrorexception-unknown-column-day0
MySQL(テーブル上)のリレーションと、ソース上のリレーションが合致してない


→テーブルを以下のようにreferencesつけて作り直した & @JoinColumn(name="id")つけてみた
======================================================================================
→ (should be mapped with insert="false" update="false")
======================================================================================
// StackOverFlowより"stupid error”
2つのテーブル間で、おんなじカラム名(idとか)同士でくっつけようとするとこのエラー吐くらしい まじか
https://stackoverflow.com/questions/15076463/another-repeated-column-in-mapping-for-entity-error
「If you have already mapped a column and have accidentaly set the same values for name and referencedColumnName in @JoinColumn hibernate gives the same stupid error

Error:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'msgdata0_.mydata_id' in 'field list'

あああああああ゛
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.testtest.SomeCustomEntity column: COLUMN_NAME (should be mapped with insert="false" update="false")」


com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'msgdata0_.msgid' in 'field list'
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'msgdata0_.mydata_id' in 'field list'
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'msgdata0_.mydata_id' in 'field list'


もう一回確認するけど

goods CREATE TABLE `goods` (

`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
`mail` varchar(20) DEFAULT NULL,
`memo` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1 |

msgdata CREATE TABLE `msgdata` (

`id` int(11)NOT NULL AUTO_INCREMENT,
`title` varchar(20) DEFAULT NULL,
`message` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |