enums

Can I use enum parameter into JpaRepository nativeQuery?

耗尽温柔 提交于 2020-06-24 11:04:08
问题 Entity looks like this: @Getter @Setter @Entity public class Application { @Id private Long id; @Enumerated(EnumType.STRING) private ApplicationStatus status; } Code works this way: public interface ApplicationRepository extends JpaRepository<Application, Long> { @Query("SELECT app FROM #{#entityName} AS app WHERE app.status LIKE :status") List<Application> find(@Param("status") ApplicationStatus status); But the same snippet with nativeQuery - doesn't: @Query(value = "SELECT app.* FROM

How to deal with enumeration 0 in C# (CA1008 discussion)

喜欢而已 提交于 2020-06-23 02:36:49
问题 Rule CA1008 specifies that all enumerations should have a 0 value that should be named Unknown (we are not discussing flags here). I understand the reason that you want to prevent that uninitialized values would automatically get a meaning. Suppose I define the following enumeration: enum Gender { Male, Female } class Person { public string Name { get; set; } public Gender Gender { get; set; } } This specifies that each person should either be male or female (let's leave out the gender

What does this colon do in an enum declaration?

孤者浪人 提交于 2020-06-22 13:36:10
问题 I did a search for this question thinking that somebody must have asked it before. I did not turn up any results, so if it has been, please post the link and feel free to close the question. I ran across this code in EASTL: enum : size_type { // size_type = size_t npos = (size_type)-1, kMaxSize = (size_type)-2 }; I have never encountered an enum declaration like that. What does the : do in this case? 回答1: This is a Microsoft extension that lets you choose the base type of the enum values. For

What does this colon do in an enum declaration?

孤人 提交于 2020-06-22 13:32:58
问题 I did a search for this question thinking that somebody must have asked it before. I did not turn up any results, so if it has been, please post the link and feel free to close the question. I ran across this code in EASTL: enum : size_type { // size_type = size_t npos = (size_type)-1, kMaxSize = (size_type)-2 }; I have never encountered an enum declaration like that. What does the : do in this case? 回答1: This is a Microsoft extension that lets you choose the base type of the enum values. For

How to define enum values that are functions?

你离开我真会死。 提交于 2020-06-22 13:31:09
问题 I have a situation where I need to enforce and give the user the option of one of a number of select functions, to be passed in as an argument to another function: I really want to achieve something like the following: from enum import Enum #Trivial Function 1 def functionA(): pass #Trivial Function 2 def functionB(): pass #This is not allowed (as far as i can tell the values should be integers) #But pseudocode for what I am after class AvailableFunctions(Enum): OptionA = functionA OptionB =

Mapping Java Enum in Postgresql with Spring Data JDBC

旧时模样 提交于 2020-06-17 02:14:26
问题 I want to be able to map a enum declared in java to an enum created in postgres. For example having the following: CREATE TYPE EYE_COLOR AS ENUM ('BROWN', 'BLUE', 'GREEN'); CREATE TABLE PERSON ( ID INT PRIMARY KEY AUTO_INCREMENT, NAME NVARCHAR2(128) NOT NULL, EYE EYE_COLOR ); In java I have something like this: public enum EyeColor { BROWN, BLUE, GREEN } public class Person { @Id Long id; String name; EyeColor eye; } When I try to do save something to the database like this: personRepository

Mapping Java Enum in Postgresql with Spring Data JDBC

╄→尐↘猪︶ㄣ 提交于 2020-06-17 02:14:24
问题 I want to be able to map a enum declared in java to an enum created in postgres. For example having the following: CREATE TYPE EYE_COLOR AS ENUM ('BROWN', 'BLUE', 'GREEN'); CREATE TABLE PERSON ( ID INT PRIMARY KEY AUTO_INCREMENT, NAME NVARCHAR2(128) NOT NULL, EYE EYE_COLOR ); In java I have something like this: public enum EyeColor { BROWN, BLUE, GREEN } public class Person { @Id Long id; String name; EyeColor eye; } When I try to do save something to the database like this: personRepository

Why can enum arrays be cast to two different IEnumerable<T> types?

二次信任 提交于 2020-06-14 06:47:51
问题 I seemed to have stumbled upon something unusual within C# that I don't fully understand. Say I have the following enum defined: public enum Foo : short { // The values aren't really important A, B } If I declare an array of Foo or retrieve one through Enum.GetValues , I'm able to successfully cast it to both IEnumerable<short> and IEnumerable<ushort> . For example: Foo[] values = Enum.GetValues( typeof( Foo ) ); // This cast succeeds as expected. var asShorts = (IEnumerable<short>) values; /

Why can enum arrays be cast to two different IEnumerable<T> types?

吃可爱长大的小学妹 提交于 2020-06-14 06:47:30
问题 I seemed to have stumbled upon something unusual within C# that I don't fully understand. Say I have the following enum defined: public enum Foo : short { // The values aren't really important A, B } If I declare an array of Foo or retrieve one through Enum.GetValues , I'm able to successfully cast it to both IEnumerable<short> and IEnumerable<ushort> . For example: Foo[] values = Enum.GetValues( typeof( Foo ) ); // This cast succeeds as expected. var asShorts = (IEnumerable<short>) values; /

Why should I never use 0 in a flag enum [duplicate]

喜你入骨 提交于 2020-06-12 07:32:30
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Should an Enum start with a 0 or a 1? Why should I never use 0 in a flag enum? I have read this multiple times now and would like to know the reason :) 回答1: Because Flag enums are bit collections, or sets of options. A 0 value would be part of all sets, or of none. It just wouldn't work. 回答2: Why should I never use 0 in a flag enum? The question is predicated on an incorrect assumption. You should always use