Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that @ Table annotations cannot be used

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to solve the problem that @ Table annotations can not be used. It has a certain reference value. Interested friends can refer to it. I hope you will learn a lot after reading this article. Let the editor take you to know it.

@ Table annotations cannot be used and report red

When I want to serialize directly when creating a new entity class, I encounter the problem that annotations don't work, and later I find that there is a lack of a dependency, which is really speechless.

@ Table (name = "tb_user") public class User implements Serializable {private static final long serialVersionUID=1L; @ Id @ GeneratedValue (strategy = GenerationType.IDENTITY) private Long id

Add the following dependency to the pom.xml file and you're done.

Javax.persistence persistence-api @ Table annotations detailed annotations spring @ Table annotations are

Declares that this object is mapped to the database's data table, through which you can specify a table (talbe) for the entity

Two commonly used attributes

1. Name is used to name the database table corresponding to the current entity class.

@ Table (name = "tab_user")

2. UniqueConstraints is used to name unique keys in batch.

Its function is equivalent to multiple: @ Column (unique = true)

Table (name = "tab_user", uniqueConstraints = {@ UniqueConstraint (columnNames= {"uid", "email"})})

Thank you for reading this article carefully. I hope the article "how to solve the problem that @ Table annotations cannot be used" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report