다음과 같이 생성 된 모델이 있습니다.
@Entity
@Table(name ="news_items")
public class NewsItem extends Model {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
public long id;
public String url;
public long friend_id;
public int count_for_the_day;
public String friend_name;
public String friend_img;
public Date friend_posted_at;
public String friend_text;
@Formats.DateTime(pattern="yyyy-MM-dd HH:mm:ss.SSS")
public Date current_time = new Date();
}
다음과 같은 방법으로 컨트롤러에 저장하려고합니다.
NewsItem _newsItem = new NewsItem();
_newsItem.url = shared_url;
_newsItem.friend_name = status.getUser().getName();
_newsItem.friend_img = status.getUser().getProfileImageURL();
_newsItem.friend_id = status.getUser().getId();
_newsItem.friend_text = status.getText();
_newsItem.friend_posted_at = status.getCreatedAt();
_newsItem.count_for_the_day = 1;
_newsItem.save();
resultItems.add(_newsItem);
값이 없습니다 null
. 활성기 콘솔에서 다음과 같은 오류가 발생합니다.
Caused by: javax.persistence.PersistenceException: ERROR executing DML bindLog[]
error[You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'current_time) values
('http://www.lahamag.com/Details/42019/119/%D8%B3%D8%B9%D9%' at line 1]
mysql DB의 변수와 관련된 부분 테이블 구조는 다음과 같습니다.
| friend_text | varchar(255) | YES | | NULL | |
| current_time | datetime | YES | | NULL | |
+-------------------+--------------+------+-----+---------+----------------+
다음과 같은 질문이 있습니다.
save()
있습니까?실행중인 값으로 전체 쿼리를 어떻게 볼 수 있습니까?
에서 application.conf 추가
db.default.logStatements=true
콘텐츠가있는 conf 폴더 내에 logger.xml 파일을 만듭니다.
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-5level - %msg%n</pattern>
</encoder>
</appender>
<logger name="com.jolbox.bonecp" level="DEBUG">
<appender-ref ref="STDOUT" />
</logger>
<logger name="play" level="DEBUG">
<appender-ref ref="STDOUT" />
</logger>
<logger name="application" level="DEBUG">
<appender-ref ref="STDOUT" />
</logger>
콘솔에서 생성 된 SQL이 표시됩니다.
이것을 해결하는 방법?
오류는 current_time 이 mysql의 예약어 이기 때문 입니다.
해결책
@Column(name="`current_time`") //backticks
public Date current_time = new Date();
트릭을 할 것입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다