休眠锁定整个表+ Lucene

时间:2019-08-06 00:53:07

标签: java mysql hibernate locking

我在aws的innodb实例中获得了锁定。支持说一切都完整无缺(明智的基础设施建设) 每当我跑步时:

  Event event = eventRdb.getObjectById(event_id, Event.class, true);
  event = eventApi.leave(event, user); //this method is below

我得到一个锁定等待,请重新启动事务,锁定的表是“用户”表。 我关闭了lucene,以为这可能是罪魁祸首,但仍然锁定。 查看事务,似乎用户表已被锁定并卡在那里。

 public Event leave(
            Event event,
            User paticipant
    ) throws CatchappException {

        if (!event.getParticipants().contains(paticipant)) {
            throw new CatchappException("Participant is not currently going to Event.");
        }

        event.getParticipants().remove(paticipant); //this part doesn't remove the participant.
        eventRdb.updateObject(event);

        if (event.getState().equals(EventState.happening)) {
            event = deleteIfNoUsers(event);
        } else {
            event = updateEventStatus(event, false);
        }
        MqttApi mqttApi = Config.injector.getInstance(MqttApi.class);
        // send chat
        Chat chat = chatApi.getOrCreateChat(ChatType.event, event);
        try {
            chatApi.addMessage(chat,
                    paticipant,
                    paticipant.getNickname() + " left this event", MessageType.text, mqttApi);
        } catch (Exception e) {
            e.printStackTrace();
        }


        return event;
    }

由于某种原因,在调用此函数时,在数据库中它显示了一个在用户上运行更新的事务,即使我没有调用它。

参与者渴望获得。

我在用户类上使用了lucene:

User.class#:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "user",
        uniqueConstraints = {
                @UniqueConstraint(columnNames = {"username"})
        },
        indexes = {
                @Index(columnList = "unique_id", name = "user_unique_id_idx")
        }
)
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@Indexed
@AnalyzerDef(name = "customanalyzer",
        tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
        filters = {
                @TokenFilterDef(factory = LowerCaseFilterFactory.class),
                @TokenFilterDef(factory = SnowballPorterFilterFactory.class),
                @TokenFilterDef(factory = StandardFilterFactory.class),
                @TokenFilterDef(factory = LowerCaseFilterFactory.class),
                @TokenFilterDef(factory = StopFilterFactory.class),
                @TokenFilterDef(factory = NGramFilterFactory.class,
                        params = {
                                @org.hibernate.search.annotations.Parameter(name = "minGramSize", value = "2"),
                                @org.hibernate.search.annotations.Parameter(name = "maxGramSize", value = "2")})})
public class User extends Persistent {

    public static final int FLAG_NONE_ROLE = 0;
    public static final int FLAG_USER_ROLE = 1;
    public static final int FLAG_ADMIN_ROLE = 2;

    private int role_flag = 0;

    @Field(index = org.hibernate.search.annotations.Index.YES, analyze = Analyze.YES, store = Store.NO, boost = @Boost(2.5f))
    @Analyzer(definition = "customanalyzer")
    private String first_name = null;

    @Field(index = org.hibernate.search.annotations.Index.YES, analyze = Analyze.YES, store = Store.NO)
    @Analyzer(definition = "customanalyzer")
    private String last_name = null;

    @Field(index = org.hibernate.search.annotations.Index.YES, analyze = Analyze.YES, store = Store.NO, boost = @Boost(2f))
    @Analyzer(definition = "customanalyzer")
    private String username = null;

    private String password = null;
    private String email = null;
    private String phone = null;
    private String phone_normalized = null;

    private String bio = null;
    private String website = null;

    private String address_street_1 = null;
    private String address_street_2 = null;
    private String city = null;
    private String state = null;
    private String country = null;
    private String zip_code = null;
    @Field(index = org.hibernate.search.annotations.Index.YES, analyze = Analyze.YES, store = Store.NO)
    private String image_url = null;
    private Set<Device> devices = new HashSet<>();

    @Convert(converter = LocalDatePersistenceConverter.class)
    private LocalDate dob = null;
    private Boolean smoker = false;
    private String hometown = null;
    private Gender gender = null;
    private Set<Language> languages = new HashSet<>();
    private Set<Event> events = new HashSet<>();
    private Long facebook_id = null;
    private String facebook_token = null;
    private String google_id = null;
    private String google_access_token = null;
    private String google_refresh_token = null;
    private DistanceUnit distance_unit = DistanceUnit.mile;
    private String external_code = null;
    private Integer num_completed_events = 0;
    private String timezone = null;
    private String verification_code = null;
    private ViewStatus view_status = null;

    @Field(index = org.hibernate.search.annotations.Index.YES, analyze = Analyze.NO, store = Store.NO)
    private Boolean verified = false;
    private Boolean needs_password_change = false;


    private Set<UserActivity> activity_profiles = new HashSet<>();
    private Set<Contact> contacts = new HashSet<>();
    private Boolean email_sent = false;

    private Set<Media> likes;
    private Set<Post> postLikes = null;
    private String api_version = "1";
    private Set<Post> posts = null;
    private Membership membership = null;

    private Boolean new_user = true;


    @Transient
    public String getNickname() {
        String nickname = "CatchApp User";
        try {
            if ((this.getFirst_name() != null) && (this.getLast_name() != null)) {
                nickname = this.getFirst_name() + " " + this.getLast_name().substring(0, 1) + ".";
            } else if (this.getFirst_name() != null) {
                nickname = this.getFirst_name();
            } else if (this.getLast_name() != null) {
                nickname = this.getLast_name();
            }
        } catch (Exception e) {
            // eat it
        }
        return nickname;
    }

    @Transient
    public String getDisplayName() {
        return getNickname();
    }


    @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
    @IndexedEmbedded
    public Set<UserActivity> getActivity_profiles() {
        return activity_profiles;
    }

    public void setActivity_profiles(Set<UserActivity> activity_profiles) {
        this.activity_profiles = activity_profiles;
    }

    public String getVerification_code() {
        return verification_code;
    }

    public void setVerification_code(String verification_code) {
        this.verification_code = verification_code;
    }

    @Type(type = "org.hibernate.type.NumericBooleanType")
    public Boolean getVerified() {
        return verified;
    }

    public void setVerified(Boolean verified) {
        this.verified = verified;
    }

    @Type(type = "org.hibernate.type.NumericBooleanType")
    public Boolean getNeeds_password_change() {
        return needs_password_change;
    }

    public void setNeeds_password_change(Boolean needs_password_change) {
        this.needs_password_change = needs_password_change;
    }

    public String getTimezone() {
        return timezone;
    }

    public void setTimezone(String timezone) {
        this.timezone = timezone;
    }

    public Integer getNum_completed_events() {
        return num_completed_events;
    }

    public void setNum_completed_events(Integer num_completed_events) {
        this.num_completed_events = num_completed_events;
    }

    public String getExternal_code() {
        return external_code;
    }

    public void setExternal_code(String external_code) {
        this.external_code = external_code;
    }

    @Transient
    public boolean isAdminRole() {
        return ((this.getRole_flag() & User.FLAG_ADMIN_ROLE) == User.FLAG_ADMIN_ROLE);
    }

    @Transient
    public boolean isUserRole() {
        return ((this.getRole_flag() & User.FLAG_USER_ROLE) == User.FLAG_USER_ROLE);
    }

    @Enumerated(EnumType.STRING)
    public DistanceUnit getDistance_unit() {
        return distance_unit;
    }

    public void setDistance_unit(DistanceUnit distance_unit) {
        this.distance_unit = distance_unit;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "event_participant_join", joinColumns = @JoinColumn(name = "participant_id"), inverseJoinColumns = @JoinColumn(name = "event_id"))
    public Set<Event> getEvents() {
        return events;
    }

    public void setEvents(Set<Event> events) {
        this.events = events;
    }

    public int getRole_flag() {
        return role_flag;
    }

    public void setRole_flag(int role_flag) {
        this.role_flag = role_flag;
    }

    public String getFirst_name() {
        return first_name;
    }

    public void setFirst_name(String first_name) {
        this.first_name = first_name;
    }

    public String getLast_name() {
        return last_name;
    }

    public void setLast_name(String last_name) {
        this.last_name = last_name;
    }

    @Column(name = "username", nullable = true, length = 64)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPhone_normalized() {
        return phone_normalized;
    }

    public void setPhone_normalized(String phone_normalized) {
        this.phone_normalized = phone_normalized;
    }

    @Column(columnDefinition = "TEXT")
    public String getBio() {
        return bio;
    }

    public void setBio(String bio) {
        this.bio = bio;
    }

    public String getAddress_street_1() {
        return address_street_1;
    }

    public void setAddress_street_1(String address_street_1) {
        this.address_street_1 = address_street_1;
    }

    public String getAddress_street_2() {
        return address_street_2;
    }

    public void setAddress_street_2(String address_street_2) {
        this.address_street_2 = address_street_2;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getZip_code() {
        return zip_code;
    }

    public void setZip_code(String zip_code) {
        this.zip_code = zip_code;
    }

    public String getImage_url() {
        return image_url;
    }

    public void setImage_url(String image_url) {
        this.image_url = image_url;
    }

    @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
    public Set<Device> getDevices() {
        return devices;
    }

    @OneToMany(mappedBy = "owner", fetch = FetchType.LAZY)
    public Set<Contact> getContacts() {
        return contacts;
    }

    public void setContacts(Set<Contact> contacts) {
        this.contacts = contacts;
    }

    public void setDevices(Set<Device> devices) {
        this.devices = devices;
    }

    // @Temporal(TemporalType.DATE)
    public LocalDate getDob() {
        return dob;
    }

    public void setDob(LocalDate dob) {
        this.dob = dob;
    }

    @Type(type = "org.hibernate.type.NumericBooleanType")
    public Boolean getSmoker() {
        return smoker;
    }

    public void setSmoker(Boolean smoker) {
        this.smoker = smoker;
    }

    public String getHometown() {
        return hometown;
    }

    public void setHometown(String hometown) {
        this.hometown = hometown;
    }

    @Enumerated(EnumType.STRING)
    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "user_language_join", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "language_id"))
    public Set<Language> getLanguages() {
        return languages;
    }

    public void setLanguages(Set<Language> languages) {
        this.languages = languages;
    }

    public Long getFacebook_id() {
        return facebook_id;
    }

    public void setFacebook_id(Long facebook_id) {
        this.facebook_id = facebook_id;
    }

    @Column(columnDefinition = "TEXT")
    public String getFacebook_token() {
        return facebook_token;
    }

    public void setFacebook_token(String facebook_token) {
        this.facebook_token = facebook_token;
    }

    public String getGoogle_id() {
        return google_id;
    }

    public void setGoogle_id(String google_id) {
        this.google_id = google_id;
    }

    public String getGoogle_access_token() {
        return google_access_token;
    }

    public void setGoogle_access_token(String google_access_token) {
        this.google_access_token = google_access_token;
    }

    public String getGoogle_refresh_token() {
        return google_refresh_token;
    }

    public void setGoogle_refresh_token(String google_refresh_token) {
        this.google_refresh_token = google_refresh_token;
    }

    public String getWebsite() {
        return website;
    }

    public void setWebsite(String website) {
        this.website = website;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(
            name = "user_likes_join",
            joinColumns = {@JoinColumn(name = "user_id")},
            inverseJoinColumns = {@JoinColumn(name = "media_id")}
    )
    public Set<Media> getLikes() {
        return likes;
    }

    public void setLikes(Set<Media> likes) {
        this.likes = likes;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(
            name = "post_likes_join",
            joinColumns = {@JoinColumn(name = "user_id")},
            inverseJoinColumns = {@JoinColumn(name = "post_id")}
    )
    public Set<Post> getPostLikes() {
        return postLikes;
    }

    public void setPostLikes(Set<Post> postLikes) {
        this.postLikes = postLikes;
    }

    public String getApi_version() {
        return api_version;
    }

    public void setApi_version(String api_version) {
        this.api_version = api_version;
    }

    @Type(type = "org.hibernate.type.NumericBooleanType")
    public Boolean getEmail_sent() {
        return email_sent;
    }
      ...
}

Event.class

    @Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "event",
        indexes = {
                @Index(columnList = "unique_id", name = "event_unique_id_idx")
        }
)
public class Event extends Persistent {
    private EventType type = null;
    private CostType cost_type = null;
    private Activity activity = null;
    private Double cost = null;
    private String currency = null;
    private Integer creator_age = null;
    private Integer creator_level = null;
    private Integer event_level = null; // for trainer course only
    private User creator = null;
    @Convert(converter = LocalDateTimePersistenceConverter.class)
    private LocalDateTime start_date = null;
    @Convert(converter = LocalDateTimePersistenceConverter.class)
    private LocalDateTime end_date = null;
    private String description = null;  //a.k.a. description ?
    private EventState state = null;
    private Gender gender = null;
    private Boolean membership_required = false;
    private Boolean trainer_event = false;
    private Double latitude = null;
    private Double longitude = null;
    private Double randomized_latitude = null;
    private Double randomized_longitude = null;
    private Boolean reminded = false;
    private Boolean shareable = false;

    //
    private String location_description = null;
    private Set<User> participants = new HashSet<>();
    private Set<EventRequest> requests = new HashSet<>();
    private Set<EventInvitation> invitations = new HashSet<>();

    private Integer participants_min = null;
    private Integer participants_max = null;
    //    private Integer participants_required = null;
    private Double distance = null;
    private String address_street_1 = null;
    private String address_street_2 = null;
    private String city = null;
    private String st = null;
    private String country = null;
    private String zip_code = null;
    private String external_code = null;
    private Boolean manually_confirmed = false;
    //    private Boolean notified_will_expire = false;
    private Boolean accept_automatically = false;
    private String title = null;
    private Boolean is_full = false;
    private String date_label = null;
    private Boolean is_spot = false;
    private Set<Media> pictures = new HashSet<>(); // up 4 images
    private String header = null; //first picture of pictures or profile picture
    private String spot_id = null;
    private LocationType location_type = null;
    private Boolean all_day = false;
    private ViewStatus view_status = null;


    @Transient
    public String getDisplayLocation() {
        if (location_description != null) {
            return location_description;
        }
        if ((city != null) && (state != null)) {
            return "near " + city + ", " + st;
        } else if (city != null) {
            return "near " + city;
        } else if (state != null) {
            return "near " + st;
        }
        if (country != null)
            return "near " + country;

        return "";
    }

    @Enumerated(EnumType.STRING)
    public LocationType getLocation_type() {
        return location_type;
    }

    public void setLocation_type(LocationType location_type) {
        this.location_type = location_type;
    }

    public Boolean getIs_full() {
        return is_full;
    }

    public void setIs_full(Boolean is_full) {
        this.is_full = is_full;
    }

    public Boolean getIs_spot() {
        return is_spot;
    }

    public void setIs_spot(Boolean is_spot) {
        this.is_spot = is_spot;
    }

    public String getHeader() {
        return header;
    }

    public void setHeader(String header) {
        this.header = header;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Type(type = "org.hibernate.type.NumericBooleanType")
    public Boolean getAccept_automatically() {
        return accept_automatically;
    }

    public void setAccept_automatically(Boolean accept_automatically) {
        this.accept_automatically = accept_automatically;
    }

    public Double getRandomized_latitude() {
        return randomized_latitude;
    }

    public void setRandomized_latitude(Double randomized_latitude) {
        this.randomized_latitude = randomized_latitude;
    }

    public Double getRandomized_longitude() {
        return randomized_longitude;
    }

    public void setRandomized_longitude(Double randomized_longitude) {
        this.randomized_longitude = randomized_longitude;
    }

    public String getExternal_code() {
        return external_code;
    }

    public void setExternal_code(String external_code) {
        this.external_code = external_code;
    }

    public String getAddress_street_1() {
        return address_street_1;
    }

    public void setAddress_street_1(String address_street_1) {
        this.address_street_1 = address_street_1;
    }

    public String getAddress_street_2() {
        return address_street_2;
    }

    public void setAddress_street_2(String address_street_2) {
        this.address_street_2 = address_street_2;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getSt() {
        return st;
    }

    public void setSt(String st) {
        this.st = st;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getZip_code() {
        return zip_code;
    }

    public void setZip_code(String zip_code) {
        this.zip_code = zip_code;
    }

    @Transient
    public Double getDistance() {
        return distance;
    }

    public void setDistance(Double distance) {
        this.distance = distance;
    }

    public Integer getEvent_level() {
        return event_level;
    }

    public void setEvent_level(Integer event_level) {
        this.event_level = event_level;
    }

    @Enumerated(EnumType.STRING)
    public EventType getType() {
        return type;
    }

    public void setType(EventType type) {
        this.type = type;
    }

    @Enumerated(EnumType.STRING)
    public CostType getCost_type() {
        return cost_type;
    }

    public void setCost_type(CostType cost_type) {
        this.cost_type = cost_type;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "activity_fk")
    public Activity getActivity() {
        return activity;
    }

    public void setActivity(Activity activity) {
        this.activity = activity;
    }

    public Double getCost() {
        return cost;
    }

    public void setCost(Double cost) {
        this.cost = cost;
    }

    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }

    public Integer getCreator_age() {
        return creator_age;
    }

    public void setCreator_age(Integer creator_age) {
        this.creator_age = creator_age;
    }

    public Integer getCreator_level() {
        return creator_level;
    }

    public void setCreator_level(Integer creator_level) {
        this.creator_level = creator_level;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "user_fk")
    public User getCreator() {
        return creator;
    }

    public void setCreator(User creator) {
        this.creator = creator;
    }


    @OneToMany(mappedBy = "event", fetch = FetchType.LAZY)
    public Set<Media> getPictures() {
        return pictures;
    }

    public void setPictures(Set<Media> pictures) {
        this.pictures = pictures;
    }

    // @Temporal(TemporalType.TIMESTAMP)
    public LocalDateTime getStart_date() {
        return start_date;
    }

    public void setStart_date(LocalDateTime start_date) {
        this.start_date = start_date;
    }

    // @Temporal(TemporalType.TIMESTAMP)
    public LocalDateTime getEnd_date() {
        return end_date;
    }

    public void setEnd_date(LocalDateTime end_date) {
        this.end_date = end_date;
    }

    // @Temporal(TemporalType.TIMESTAMP)
//    public LocalDateTime getEnd_of_life_date() {
//        return end_of_life_date;
//    }
//
//    public void setEnd_of_life_date(LocalDateTime end_of_life_date) {
//        this.end_of_life_date = end_of_life_date;
//    }

    @Column(columnDefinition = "TEXT")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Enumerated(EnumType.STRING)
    public EventState getState() {
        return state;
    }

    public void setState(EventState state) {
        this.state = state;
    }

    @Enumerated(EnumType.STRING)
    public Gender getGender() {
        return gender;
       ...

这是几天前突然开始的事情。仅在某些事件下发生。一旦我致电leave(),它就会阻止,无法编辑任何事件。

0 个答案:

没有答案
相关问题