Моё java-приложение работает с БД под SQL. После добавления в БД новой таблицы “paragraph_type” и новой связанной колонки “PARTYPE_ID” в таблицу “paragraphs” появились ошибки:
Локальная СУБД mysql Ver 15.1 Distrib 10.3.13-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2. ДЛя взаимодействия с ней используется springframework и hibernate.
Эти топики мне не помогли:
Структура новой таблицы "paragraph_type":
CREATE TABLE `paragraph_type` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`PARTYPE` char(3) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
Структура таблицы "paragraphs":
CREATE TABLE `paragraphs` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`PARTYPE_ID` bigint(20) unsigned NOT NULL DEFAULT 1, //NEW
`PID` int(11) DEFAULT NULL,
`CODE` varchar(255) DEFAULT '',
`CONTENT` longtext DEFAULT NULL,
`DOCUMENT_ID` int(11) DEFAULT NULL,
`APPENDIX` tinyint(4) NOT NULL DEFAULT 0,
`APPENDIX_NAME` varchar(255) DEFAULT '',
PRIMARY KEY (`ID`),
KEY `DOCUMENT_ID` (`DOCUMENT_ID`),
KEY `pid_key` (`PID`),
KEY `p_type_key` (`PARTYPE_ID`),
CONSTRAINT `p_type_key` FOREIGN KEY (`PARTYPE_ID`) REFERENCES `paragraph_type` (`ID`),
CONSTRAINT `paragraphs_ibfk_1` FOREIGN KEY (`PID`) REFERENCES `paragraphs` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=18823 DEFAULT CHARSET=utf8
Класс "Paragraph.java":
...
@Entity
...
@Table(name = "paragraphs")
public class Paragraph implements INodeEntity, Comparable {
...
private long id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@NotNull(message = "802")
private ParagraphsType paragraphsType;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "PARTYPE_ID")
public ParagraphsType getParagraphsType(){
return paragraphsType;
}
public void setParagraphsType(ParagraphsType paragraphsType){
this.paragraphsType = paragraphsType;
}
...
@NotNull(message = "802")
private NormativeDocument normativeDocument;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "DOCUMENT_ID")
public NormativeDocument getNormativeDocument() {
return normativeDocument;
}
public void setNormativeDocument(NormativeDocument normativeDocument) {
this.normativeDocument = normativeDocument;
}
....
}
Класс "ParagraphsType.java":
....
@Entity
@Table(name = "paragraph_type")
public class ParagraphsType implements IEntity {
private long id;
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public long getId() {
return id;
}
@Override
public void setId(long id) {
this.id = id;
}
private char[] paragraphsType = new char[3];
@Column(name = "PARTYPE_ID")
public char[] getParagraphsType() {
return paragraphsType;
}
public void setParagraphsType(char[] paragraphsType) {
this.paragraphsType = paragraphsType;
}
...
}
xml-файл: "pr.xml":
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="providersRepository" class="ru.leasoft.armspk.ProvidersRepository" factory-method="get"
lazy-init="false" scope="singleton" init-method="initDatasourceMap">
...
<property name="paragraphs" ref="paragraphsDao"/>
<property name="paragraphType" ref="paragraphTypeDao"/>
...
</bean>
</beans>
Класс провайдера для таблицы "paragraphs" "ParagraphsProvider.java":
@Repository("paragraphsDao")
public class ParagraphsProvider implements Paragraphs {
...
@Resource(name = "sessionFactory")
private SessionFactory sessionFactory;
public List<Paragraph> getAll() {
...
throw new RuntimeException("Unsupported operation: getAll()");
}
@Transactional(readOnly = true)
public Paragraph getById(long id) {
Paragraph paragraph = (Paragraph) sessionFactory.getCurrentSession().get(Paragraph.class, id);
if (paragraph == null) {
throw new BadRequestException("3");
}
...
return paragraph;
}
...
}
Класс провайдера для таблицы "paragraph_type" "ParagraphsTypesProvider.java":
@Repository("paragraphTypeDao")
public class ParagraphsTypesProvider implements CRUDDatasource<ParagraphsType>, FilteringProvider<ParagraphsType> {
@Resource(name = "sessionFactory")
private SessionFactory sessionFactory;
@Resource(name = "permissionChecker")
private PermissionChecker permissionChecker;
private FilterPaginator filterPaginator = new FilterPaginator(ParagraphsType.class);
@Override
public FilteredResult filterAll(Filter filter) {
return filterPaginator.doFiltration(sessionFactory.getCurrentSession(), filter);
}
...
}
Лог об ошибках при выполнении:
WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - <SQL Error: 1054, SQLState: 42S22>
ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - <Unknown column 'paragraphs4_.PARTYPE_ID' in 'field list'>
ERROR [org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler] - <Unexpected error occurred in scheduled task.>
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:80)
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'paragraphs4_.PARTYPE_ID' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - <SQL Error: 1054, SQLState: 42S22>
ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - <Unknown column 'paragraphs0_.PARTYPE_ID' in 'field list'>
WARN [org.hibernate.engine.loading.internal.LoadContexts] - <HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@4bb96906<rs=com.mchange.v2.c3p0.impl.NewProxyResultSet@4a1a93e8>>
WARN [org.hibernate.engine.loading.internal.CollectionLoadContext] - <HHH000160: On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [1] entries>
ERROR [org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler] - <Unexpected error occurred in scheduled task.>
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:80)
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'paragraphs0_.PARTYPE_ID' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
Как избежать этого исключения?
У Вас в DDL таблицы paragraph_type
описаны колонки ID
и PARTYPE
. А в классе, на который мапится табличка описаны @Column(name = "ID")
и @Column(name = "PARTYPE_ID")
. Отсюда и ошибка. Сделайте в классе ParagraphsType
@Column(name = "PARTYPE")
и думаю будет Вам счастье.
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Запускаю сервер все настроил хорошо, но ничего не работаетПомогите сижу уже 3 день с Tomcat
Имеется div блок с картинкой, внутри этого блока еще один - так же с картинкой (лайк)