Рассмотрим следующую простую иерархию: < /p>
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Setter
@Getter
public class Brand {
@Id
Long id;
String name;
}
@Entity
@Setter
@Getter
public class BrandDetail extends Brand {
private String wpCode;
}
Предположим, что у нас есть строка в таблице бренда с идентификатором 1l и без соответствующего brand_detail row.
Следующее: < /p>
@Service
public class BrandService {
@Autowired
private BrandRepository brandRepository;
@Autowired
private BrandDetailRepository brandDetailRepository;
public void addBrandDetails(Long brandId, String wpCode) {
// Fetch the existing Brand entity
Brand brand = brandRepository.findById(brandId).orElseThrow(() -> new EntityNotFoundException("Brand not found"));
// Create a BrandDetail entity
BrandDetail brandDetail = new BrandDetail();
brandDetail.setId(brand.getId()); // Set the same ID as the existing Brand
brandDetail.setName(brand.getName()); // Copy the existing fields
brandDetail.setWpCode(wpCode); // Set the new detail
// Save the BrandDetail entity
brandDetailRepository.save(brandDetail);
}
}
< /code>
Не удается с: < /p>
Hibernate: select b1_0.id,case when b1_1.id is not null then 1 when b1_0.id is not null then 0 end,b1_0.name,b1_1.wp_code from brand b1_0 left join brand_detail b1_1 on b1_0.id=b1_1.id where b1_0.id=?
2025-01-30T16:23:23.680+01:00 TRACE 219372 --- [demo] [ main] org.hibernate.orm.jdbc.bind : binding parameter (1:BIGINT)
Подробнее здесь: https://stackoverflow.com/questions/794 ... ted-tables
Jpa inheritancetype. ⇐ JAVA
Программисты JAVA общаются здесь
1738254933
Anonymous
Рассмотрим следующую простую иерархию: < /p>
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Setter
@Getter
public class Brand {
@Id
Long id;
String name;
}
@Entity
@Setter
@Getter
public class BrandDetail extends Brand {
private String wpCode;
}
Предположим, что у нас есть строка в таблице бренда с идентификатором 1l и без соответствующего brand_detail row.
Следующее: < /p>
@Service
public class BrandService {
@Autowired
private BrandRepository brandRepository;
@Autowired
private BrandDetailRepository brandDetailRepository;
public void addBrandDetails(Long brandId, String wpCode) {
// Fetch the existing Brand entity
Brand brand = brandRepository.findById(brandId).orElseThrow(() -> new EntityNotFoundException("Brand not found"));
// Create a BrandDetail entity
BrandDetail brandDetail = new BrandDetail();
brandDetail.setId(brand.getId()); // Set the same ID as the existing Brand
brandDetail.setName(brand.getName()); // Copy the existing fields
brandDetail.setWpCode(wpCode); // Set the new detail
// Save the BrandDetail entity
brandDetailRepository.save(brandDetail);
}
}
< /code>
Не удается с: < /p>
Hibernate: select b1_0.id,case when b1_1.id is not null then 1 when b1_0.id is not null then 0 end,b1_0.name,b1_1.wp_code from brand b1_0 left join brand_detail b1_1 on b1_0.id=b1_1.id where b1_0.id=?
2025-01-30T16:23:23.680+01:00 TRACE 219372 --- [demo] [ main] org.hibernate.orm.jdbc.bind : binding parameter (1:BIGINT)
Подробнее здесь: [url]https://stackoverflow.com/questions/79400483/jpa-inheritancetype-joined-complete-partially-popolated-tables[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия